y2yang Posted May 2, 2009 Share Posted May 2, 2009 I need help in making this pagination programmed rather than hard coded. <table width="100%"> <tr style="height:33px;background:#f3f3f3;"> <td class="tac vam"><span class="fs11"><img src="http://image.vickizhao.net/style_guide/icn/icn_starhome_prevfirst.gif" class="vat" alt="PREV FIRST" style="margin:2px; 0 0 0;" /> <img src="http://image.vickizhao.net/style_guide/icn/icn_starhome_prev1.gif" class="vat" alt="PREV" style="margin: 2px;"> <span class="b fs11 fc7">1</span><span class="fs10 fc7"> / </span><a class="fs11 fc7" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=2">2</a><span class="fs10 fc7"> / </span><a class="fs11 fc7" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=3">3</a><span class="fs10 fc7"> / </span><a class="fs11 fc7" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=4">4</a><span class="fs10 fc7"> / </span><a class="fs11 fc7" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=5">5</a><span class="fs10 fc7"> / </span><a class="fs11 fc7" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=6">6</a><span class="fs10 fc7"> / </span><a class="fs11 fc7" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=7">7</a><span class="fs10 fc7"> / </span><a class="fs11 fc7" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=8">8</a><span class="fs10 fc7"> / </span><a class="fs11 fc7" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=9">9</a><span class="fs10 fc7"> / </span><a class="fs11 fc7" href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=10">10</a> <a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=11" onfocus='this.blur();' style='text-decoration:none;'><img src="http://image.vickizhao.net/style_guide/icn/icn_starhome_next1.gif" class="vat" alt="NEXT" style="margin:2px; 0 0 0;" /></a> <a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/starhome/photo/list.php?Pid=11" onfocus='this.blur();' style='text-decoration:none;'><img src="http://image.vickizhao.net/style_guide/icn/icn_starhome_nextlast.gif" class="vat" alt="NEXT" style="margin:2px; 0 0 0;" /></a></span></td> </tr> </table> Here is an example of what I have it in hard coded: I would like for current page to be bold, with a next, last, prev, first link at all time. The code I'm looking into is the one famous "Basic pagination" on this forum: /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_prevfirst.gif' class='vat' alt='PREV FIRST' style='margin:2px; 0 0 0;'></a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_prev1.gif' class='vat' alt='PREV' style='margin: 2px;'></a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " <span class='b fs11'>$x</span> "; // if not current page... } else { // make it a link echo " <span class='fs11'><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a></span> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'><img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_next1.gif' class='vat' alt='NEXT' style='margin:2px; 0 0 0;'></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'><img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_nextlast.gif' class='vat' alt='NEXT' style='margin:2px; 0 0 0;'></a> "; } // end if /****** end build pagination links ******/ Any help please. :'( Quote Link to comment https://forums.phpfreaks.com/topic/156532-help-make-this-pagina-automatic/ Share on other sites More sharing options...
ignace Posted May 2, 2009 Share Posted May 2, 2009 http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/156532-help-make-this-pagina-automatic/#findComment-824219 Share on other sites More sharing options...
y2yang Posted May 2, 2009 Author Share Posted May 2, 2009 I have red through the tutorial but I don't know how to get the / in between the #. example: 1 / 2 / 3 Anyhelp? Quote Link to comment https://forums.phpfreaks.com/topic/156532-help-make-this-pagina-automatic/#findComment-824223 Share on other sites More sharing options...
premiso Posted May 2, 2009 Share Posted May 2, 2009 for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... $slash = ($x != ($currentpage - $range) || $x != $totalpages)?"/":""; if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " <span class='b fs11'>$x</span> {$slash}"; // if not current page... } else { // make it a link echo " <span class='fs11'><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a></span> {$slash}"; } // end else } // end if } // end for Give that a try for the for loop. Quote Link to comment https://forums.phpfreaks.com/topic/156532-help-make-this-pagina-automatic/#findComment-824280 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.