I know this probably super simple but its been driving me nuts for a couple of hours now...

what i want to do is display results from a database query in blocks of six - then link to the other pages with a next button... I have this working great, only problem is i want to show the user what page they're on and how many other pages there are left to show...

ie; "your are viewing page 1 of 6"

I have the amount of matched records with $num = mysql_num_rows($Globalresult);

i tried $numberofpages = $round($num / 6); but obviously if there are thirteen records it will think there are only two pages of results...

if anyone could help that would be awesome...

cheers

    There is a pretty good article about this on this site.

    I ended up writting my own, though.
    You're on the right track. Divide by 6 then check if there is a remainder. If there is, add 1 if not use the result.
    You have to then do another query with offset and limit to display the results.

    You're almost there.

      Try using [man]ceil[/man] instead of round...

        ceil() seems to do the trick - just need to work out the best way to actually work out the current page number...

          $NumPerPage = 10;
          
          if(!isset($pageNum))
             {
             $pageNum = 0;
             }
          
          $SQL .= "$SELECT * FROM Table LIMIT ". $pageNum * $NumPerPage .",$NumPerPage ";
          
          $result ...
          while(...)
          
          if($pageNum != 0)
             {
             $PrevCount = $pageNum - 1;
          
             echo"<a href=\"?pageNum=$PrevCount\">Previous Page</a>\n";
             }
          $i = 0;
          while($i <= $NumOfPages - 1)
             {
             $x = $i + 1;
             if($i != $pageNum)
                {
                echo"<a href=\"?pageNum=$i\">[ $x ]</a> \n";
                }
             else
                {
                echo"[$x ] ";
                }
             $i ++;
             }
          
          if($pageNum != $NumOfPages - 1)
             {
             $NextCount = $pageNum + 1;
          
             <a href=\"?pageNum=$NextCount\">Next Page</a>\n";
             }
          

          Hope this helps

            Write a Reply...