Jump to content


Photo

pagnation tutorial


  • Please log in to reply
2 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 22 September 2006 - 11:47 AM

http://www.phpfreaks...orials/73/0.php

I need help with the above.

I can get the code to work fine and have it working, but what I want to add is

Showing: 1 - 10 of 34 results...

i can do all of it apart from where the 10 is i can do this with the code below, but when it gets to the last page it goes 71 - 80 but should be 71 - 73

  $max_results = 10;
  $from = (($p * $max_results) - $max_results);
  $page_from = $from + 1;    
  $page_to = $page_from + 9;  
  $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM testimonials"),0);
  $total_pages = ceil($total_results / $max_results);
     
echo"      <table width='695' border='0' cellspacing='0' cellpadding='0'>";
echo"        <tr>
              <td class='text_red_bold'>Showing: $page_from - $page_to of $total_results testimonials</td>
            </tr>";

http://www.randomhom...action=view&p=8

#2 radalin

radalin
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 22 September 2006 - 11:50 AM

try
         $page_to = ( (page_from + 9) > $total_results ? $total_results : (page_from + 9)  ) ;

but you have to first assign total_results and then assign page_to
Roy Simkes
Yet Another Parkyeri Developer

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 22 September 2006 - 12:07 PM

  $max_results = 10;
  $from = (($p * $max_results) - $max_results);

  $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM testimonials"),0);
  $total_pages = ceil($total_results / $max_results);
 
  $page_from = $from + 1;    
  $page_to = ( (page_from + 9) > $total_results ? $total_results : (page_from + 9)  ) ;

hey works fine, thanks very much....

oh i had to put the $ in front of page_from as u missed it




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users