phpQuestioner Posted November 26, 2007 Share Posted November 26, 2007 I had an idea last night to create a pagination script based on mysql limit and I saw a thread just a little bit ago that sparked my interest in doing something similar with my script as the script in that thread. I want to be able to limit how many pagination numbers can be seen at one time, but I want them to count up or down with the pagination and for the pagination urls to change - similar to a Google Search Results pagination. Here Is Most of The Full Code: <?php // connect // select db $thispage = $_SERVER['PHP_SELF']; $amount = $_GET['skip']; $next = $amount + $display; $back = $amount - $display; $results = mysql_query("select * from $mydt LIMIT $amount, $display"); $maxed_out = mysql_num_rows(mysql_query("select * from $mydt")); $total_amount_of_pgs = $maxed_out / $display; $currentpg = $amount / $display; $tp = ceil($total_amount_of_pgs); if ($currentpg > $total_amount_of_pgs) { $currentpg = $total_amount_of_pgs; } while($this=mysql_fetch_array($results)) { // declare variables $myfield=$this["field1"]; // display content echo "$myfield<br>"; } // Pagination echo "<br><center>"; echo "<a href=\"$thispage?skip=$back\">Previous<a>"; for ($i = 0; $i < $tp; $i++) { $pganteqty = $display * $i; $ci = $i + 1; if ($ci<=3) { echo " <a href=\"$thispage?skip=$pganteqty\">$ci</a> "; } else { echo " ........ "; break; } } echo "<a href=\"$thispage?skip=$next\">Next<a>"; echo "<br><br>"; echo "Viewing Page ". floor($currentpg + 1) ." of ". ceil($total_amount_of_pgs) .""; echo "</center>"; ?> And Here Is The Segment I'm Having Problems With: for ($i = 0; $i < $tp; $i++) { $pganteqty = $display * $i; $ci = $i + 1; if ($ci<=3) { echo " <a href=\"$thispage?skip=$pganteqty\">$ci</a> "; } else { echo " ........ "; break; } } The above code will show only three numbers at a time, but it will not count up or down and it will not change pagination numbers or pagination urls. How can I do this with my script? Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 26, 2007 Share Posted November 26, 2007 ignore.. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 26, 2007 Author Share Posted November 26, 2007 teng84 - what is your problem? - I just do not understand how to do this. not all of us are perfect coders like yourself. could someone tell me how to do this? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 26, 2007 Author Share Posted November 26, 2007 ok - can someone point me in the direction of a good tutorial on how this can be done? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 26, 2007 Share Posted November 26, 2007 This looks similar to your paging you can modify it, i am using these function to show paging... <?php ## function to show paging....... function showPaging($curpage) { global $sCurpageurl; global $offset; global $limit; global $nTotalrows; global $nTotalpage; global $sOrderpagetype; global $sOrderfield; echo" <table width=100% border=0 cellspacing=0 cellpadding=5 >"; echo "<tr>"; $lastrowno=$offset+$limit; if($lastrowno>=$nTotalrows) $lastrowno=$nTotalrows; if($nTotalrows==0) $startrow=0; else $startrow=$offset+1; echo"<td align=left width=50% ><b></b> " .$startrow ." - ". ($lastrowno) ." of ". $nTotalrows ."</td>"; echo"<td align=right width=50% >"; echo "<b>Page : </b>"; for($i=1;$i<=$nTotalpage;$i++) { $curOffset=($i-1)*$limit; if($i==$curpage) echo "<b> ".$i."</b>"; else if ( strpos($sCurpageurl,"?")>0) { echo" <a href=".$sCurpageurl."&offset=".$curOffset."&pno=".$i."&field=".$sOrderfield."&pord=".$sOrderpagetype." admin_menu_link>".$i."</a>" ; } else { echo" <a href=".$sCurpageurl."?offset=".$curOffset."&pno=".$i."&field=".$sOrderfield."&pord=".$sOrderpagetype." admin_menu_link>".$i."</a>" ; } } echo"</td></tr></table>"; } ## function to show total pages....... function totalPages($strsql){ global $limit; global $nTotalrows; global $nTotalpage; $rs1=mysql_query($strsql)or die("query failed11".mysql_error()); $rowno=mysql_num_rows($rs1); if($rowno>0) $nTotalpage=ceil($rowno/$limit); else $nTotalpage=0; $nTotalrows=$rowno; } ?> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 26, 2007 Author Share Posted November 26, 2007 ~n[EO]n~ I put your function/script in my while condition; it limited the rows to 2, but it would not display the pagination. - Thank You Though Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.