Jump to content

Recommended Posts

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:

pagination.jpg

 

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.

 

:'(

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/156532-help-make-this-pagina-automatic/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.