y2yang Posted May 3, 2009 Share Posted May 3, 2009 How to make this programmed rather than doing it hard coded by hand on every pages. Would be like living in stone age ??? Here is the code I used, will explain further down exactly what I'm seeking. <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 how the code looks like on my page http://vickizhao.net/starhome/photo/list.php?Pid=2 What I wanted to do is have the selected # in bold to correlated to my URL page id i.e. list.php?id=2 would have the pagination 2 in bold like in the image. I can do this perfectly hard coded but not sure how to do it programmed. I have looked over the "Basic Pagination" example but I not sure how to change it to make it look like the one show in the image. On every page id is 8 images; 4 on top 4 on bottom with the pagination on bottom. Thank you. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 So are you asking for pagination or just to bold the number the page is on? Quote Link to comment Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 Both Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 Do you have a PHP working code that I may look at? Quote Link to comment Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 It's from the "Basic Pagination" posted on this forum, with minor fix/touch only. <?php /****** 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 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 // 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 ******/ ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 <?php /****** 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 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' style='font-weight: bold;'>$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 // 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 ******/ Yes? Quote Link to comment Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 Thank you but wasn't what i looking for. Here is a better code for you to get an idea: <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> I put this into a php page and uploaded to the site: vickizhao.net/pagination2.php With my css and it should look like vickizhao.net/starhome/photo/list.php?Pid=2 I wanted to make it programmed rather than hard coded. Each of the #s correlated to the URL id, bold 5 = URL id 5. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 That's too hard to read! The whole thing is all in one line. Can you put proper line breaks and indentations? Quote Link to comment Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 The First and Prev has no link as this is the first 10 set but has Next and Last. The selected number is spanned to be b=bold, fs11=font size 11px, fc7=font color. <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> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 Is there anyway to know how many pages there are in total? If not, then this is the best I can do. <?php /****** build the pagination links ******/ // range of num links to show $range = 3; $totalpages = 10; // get currentpage $currentpage = (int) $_GET['Pid']; // if not on page 1, don't show back links if ($currentpage < 10) { // show << image echo "<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;'> "; } else { // show << link to go back to page 1 echo "<a href='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=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='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=$prevpage'><img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_prev1.gif' class='vat' alt='PREV' style='margin: 2px;'></a> "; } // end if 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 fc7'>$x</span>"; // if not current page... } else { // make it a link echo "<a class='fs11 fc7' href='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=$x'>$x</a>"; } // end else echo '<span class="fs10 fc7'> / </span>'; } // 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='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=$nextpage' 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> "; // echo forward link for lastpage echo "<a href='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=$totalpages' 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>"; } // end if else { echo "<img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_next1.gif' class='vat' alt='NEXT' style='margin:2px; 0 0 0;'> <img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_nextlast.gif' class='vat' alt='NEXT' style='margin:2px; 0 0 0;'>"; } /****** end build pagination links ******/ Quote Link to comment Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 You're the best Ken2ky. Yes there is a way to know the exact total pages in total. If I keep track of how many images I have uploaded, and divide that by 8 (total images per page), than I get the total pages. Kinda old school but it work, and the hard part is already taking care of by you. Thank you again. Solved, for now hehe, the road is till long ahead. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 Wow, I hadn't noticed it earlier, but there's an error in my script. Here's the modified script to display 1 - 10, and only 1 - 10. <?php /****** build the pagination links ******/ $totalpages = 10; // get currentpage $currentpage = (int) $_GET['Pid']; // if not on page 1, don't show back links if ($currentpage < $totalpages) { // show << image echo "<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;'> "; } else { // show << link to go back to page 1 echo "<a href='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=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='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=$prevpage'><img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_prev1.gif' class='vat' alt='PREV' style='margin: 2px;'></a> "; } // end if for ($x = 1; $x <= $totalpages; $x++) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " <span class='b fs11 fc7'>$x</span>"; // if not current page... } else { // make it a link echo "<a class='fs11 fc7' href='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=$x'>$x</a>"; } // end else echo '<span class="fs10 fc7"> / </span>'; } // 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='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=$nextpage' 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> "; // echo forward link for lastpage echo "<a href='http://{$_SERVER['SERVER_NAME']}/starhome/photo/list.php?Pid=$totalpages' 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>"; } // end if else { echo "<img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_next1.gif' class='vat' alt='NEXT' style='margin:2px; 0 0 0;'> <img src='http://image.vickizhao.net/style_guide/icn/icn_starhome_nextlast.gif' class='vat' alt='NEXT' style='margin:2px; 0 0 0;'>"; } /****** end build pagination links ******/ 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.