faqts : Computers : Programming : Languages : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

15 of 29 people (52%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How can I use PHP to display results by page (Like in Google)

Feb 1st, 2000 12:43
Matt Gregory, Rory Toop,


First, figure out how many items you are going to list on each 
page for results.  For the purpose of this example I'll say 10 per 
page.  So then take the number of results returned by the query and 
divide them by 10.  Then just pass the query back to the show results 
script and have it do the math and figure out which of the results in 
the result script to return.
<? //loop to show page numbers.
    echo "<a href="show_page.php3?Query=$Query&PageNum="; 
    echo $PageNum - 1 . "\"><<Prev</a>\n";
    for($ndex = 1; $ndex <= ($Numresults / $Numperpage); $ndex++)
    {
        if($ndex == $PageNum)
	    echo "<b>";
        echo "<a href="show_page.php3?Query=$Query&PageNum=";
        echo $ndex . "\">" . $ndex . ">></a>\n";
        if($ndex == $PageNum)
            echo "</b>";
    }
    echo "<a href="show_page.php3?Query=$Query&PageNum="
    echo "$PageNum + 1 . "\">Next>></a>\n";
?>