Dear All;
i would like to ask how to divide data among pages like what yahoo mails did when you read your mails for example the first page contains 10 mails when you press next page , the you go to page 2 which contains another 10 mails , i want to make something like this so that i can show my products in a sequence of pages according to my database
dasatti 0 Junior Poster in Training
Hi,
You have do develop you own logic for that. Their is no direct way. May be you can find some class on phpclasses.net which lets you easily create pagination but I do it without any class. I am pasting here a function from my code which includes pagination. You can get basic idea how it is done. If you have any difficulty understanding the code or have nay question let me know. I can help you create pagination if you paste your code here.
I am attaching code in a file since it is too long.
thanks
function listPendingMembers()
{
$list_member_output="";
$list_output="";
$records_per_page=25;
$page_no=1;
$initial_record=0;
if(isset($_REQUEST['page']))
{
$page_no=$_REQUEST['page'];
$initial_record=($page_no-1)*$records_per_page;
}
$q="SELECT * FROM members WHERE mem_isactivated=0";
$init_letter="";
if(isset($_GET['alpha']))
{
$init_letter = $_GET['alpha'];
}
if (isset($_REQUEST['inp_userId']) && strlen(trim($_REQUEST['inp_userId']))>0 ) {
$q.=" AND mem_nick LIKE '%".$_REQUEST['inp_userId']."%'";
}
else
$q.=" AND mem_nick LIKE '".$init_letter."%'";
if (isset($_POST['sel_mebership_status']) && $_POST['sel_mebership_status']!="any") {
$q.=" AND mem_isactivated=".$_POST['sel_mebership_status']."";
}
if (isset($_POST['sel_registration_status']) && $_POST['sel_registration_status']!="any") {
if($_POST['sel_registration_status']=="" or $_POST['sel_registration_status']=="na")
{
$q.=" AND (registration_status ='' OR registration_status='na')";
}
else
$q.=" AND registration_status ='".$_POST['sel_registration_status']."'";
}
if(isset($_REQUEST['inp_sort_by']) && trim($_REQUEST['inp_sort_by'])!="")
{
$q.=" ORDER BY ";
$q.=$_REQUEST['inp_sort_by'];
$q.=" ";
if(isset($_REQUEST['inp_sort_method']) && trim($_REQUEST['inp_sort_method'])!="")
$q.=$_REQUEST['inp_sort_method'];
}
$q1=$q;
$q.=" LIMIT $initial_record , $records_per_page";
$r_total_records=mysql_query($q1);
$total_records=mysql_num_rows($r_total_records);
$total_pages=ceil($total_records/$records_per_page);
$rs=mysql_query($q);
$list_member_output.="<table width=\"95%\" align=\"center\">";
$list_member_output.="<tr>";
$list_member_output.="<th>Index</th><th>User ID</th><th>Email</th><th>Reg. Status</th><th>Mem. Status</th><th>Joined On</th><th>Actions</th>";
$list_member_output.="</tr>";
if(mysql_num_rows($rs)>0)
{
//$x=0;$row=1;
$x=0;$row=$initial_record+1;
while($x<mysql_num_rows($rs))
{
$list_member_output.="<form action=member_listing.php?menu=approve&action=do_approve method=post>";
$list_member_output.="<input type=hidden name=hdn_id value=\"".mysql_result($rs,$x,'memberid')."\">";
$list_member_output.="<tr class=light_tr><td>".$row."</td>";
$list_member_output.="<td><a href=member_listing.php?action=mem_detail&mem_id=".mysql_result($rs,$x,'memberid').">".mysql_result($rs,$x,'mem_nick')."</a></td>";
$list_member_output.="<td>".mysql_result($rs,$x,'mem_email')."</td>";
$membership_status="pending";
if (mysql_result($rs,$x,'mem_isactivated')==1) {
$membership_status="active";
}
if (mysql_result($rs,$x,'mem_isactivated')==-1) {
$membership_status="blocked";
}
if (mysql_result($rs,$x,'mem_isactivated')==-2) {
$membership_status="deleted";
}
$registration_status=mysql_result($rs,$x,'registration_status');
if (trim($registration_status)==null) {
$registration_status="NA";
}
$list_member_output.="<td>".$registration_status."</td>";
$list_member_output.="<td>".$membership_status."</td>";
$list_member_output.="<td>".mysql_result($rs,$x,'mem_joindate')."</td>";
$list_member_output.="<td align=center><input type=\"submit\" value=\"Approve\" name=\"btn_submit\"></td>";
$list_member_output.="</tr></form>";
$list_output.="<tr><td>".$row."</td><td>".mysql_result($rs,$x,'mem_nick')."</td>";
$list_output.="<td>".mysql_result($rs,$x,'mem_email')."</td>";
$list_output.="<td>".mysql_result($rs,$x,'mem_joindate')."</td></tr>";
$x++;
$row++;
}
$t_pages = $total_pages;
$page = $page_no;
$currentPage = $page;
$groupFirst = $page;
$previousGroupFirst = $page;
$nextGroupFirst = $page;
$previousLargeGroupFirst = $page;
$nextLargeGroupFirst = $page;
$disableFirst = false;
$disableLast = false;
$disablePreviousGroup=false;
$disableNextGroup=false;
$disableLargeGroupNext=false;
$disableLargeGroupPrevious=false;
for ($g=$currentPage;$g>=$currentPage-5;$g--)
{
if ( $g==1 || ($g%5)==0) {
$groupFirst = $g;
if ($groupFirst-1<=0) {$previousGroupFirst = 1; $disablePreviousGroup = true;}
else $previousGroupFirst = $groupFirst - 1;
if ($groupFirst+5>$t_pages) {$nextGroupFirst = $groupFirst; $disableNextGroup = true;}
else $nextGroupFirst = $groupFirst+5;
if ($groupFirst-10<=0) {$previousLargeGroupFirst = 1;$disableLargeGroupPrevious = true;}
else $previousLargeGroupFirst = $groupFirst - 10;
if ($groupFirst+10>$t_pages) {$nextLargeGroupFirst = $groupFirst; $disableLargeGroupNext=true;}
else $nextLargeGroupFirst = $groupFirst+10;
break;
}
}
$grouplast = $groupFirst+5;
if ($page==1) {
$disableFirst = true;
}
if ($page==$t_pages) {
$disableLast = true;
}
$url = "member_listing.php?menu=approve&alpha=".$init_letter;
$pagination_output="";
$pagination_output.="<tr><td colspan=100 align=center>";
if(!$disableFirst)
$pagination_output.=" <a href=$url&page=1 title=\"First\">|<</a> ";
else $pagination_output.=" |< ";
if(!$disableLargeGroupPrevious)
$pagination_output.=" <a href=$url&page=$previousLargeGroupFirst title=\"Previous (10)\"><<<</a> ";
else $pagination_output.=" <<< ";
if(!$disablePreviousGroup)
$pagination_output.=" <a href=$url&page=$previousGroupFirst title=\"Previous (5)\"><<</a> ";
else $pagination_output.=" << ";
for($i=$groupFirst;$i<$grouplast && $i<=$t_pages;$i++)
{
$pagination_output.="<a href=$url&page=$i title=\"Page $i\">";
if ($currentPage==$i) {
$pagination_output.="<b>$i</b>";
}
else{
$pagination_output.=$i;
}
$pagination_output.="</a> ";
}
if (!$disableNextGroup)
$pagination_output.=" <a href=$url&page=$nextGroupFirst title=\"Next (5)\">>></a> ";
else $pagination_output.=" >> ";
if (!$disableLargeGroupNext)
$pagination_output.=" <a href=$url&page=$nextLargeGroupFirst title=\"Next (10)\">>>></a> ";
else $pagination_output.=" >>> ";
if(!$disableLast)
$pagination_output.=" <a href=$url&page=$t_pages title=\"Last\">>|</a> ";
else $pagination_output.=" >|";
$pagination_output.="</td></tr>";
$pagination_output.="<tr><td colspan=100 align=center>";
$pagination_output.="Showing page <b>$page</b> of <b>$t_pages</b>";
$pagination_output.="</td></tr>";
$pagination_output.="</table></p>";
$list_member_output.=$pagination_output;
// $list_trans_paging.=$pagination_output;
}
else
{
$list_member_output="<tr class=\"light_tr\"><td colspan=\"5\" align=\"center\"><div class=error>No member found pending for membership approvel</div></td></tr>";
}
$list_member_output.="</table>";
echo $list_member_output;
}
Abdel_eid -5 Junior Poster in Training
dasatti thank you very much i will try it and will tell you if i have any difficulty in understanding the code
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.