RE: [PHP] Search Result Navigation

From: Date: Tue, 05 Dec 2000 00:10:45 +0000
Subject: RE: [PHP] Search Result Navigation
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28670@lists.php.net to get a copy of this message
Here is a simple function that can be expanded upon. Call it with the following line (overcommented so you get the feel of things) First we assume your database call is something like: query="SELECT * FROM MyTable WHERE MyColumn=$DB_Result"; ... # $DB_Result to pass back to this page when the next page is requested # $TotalResults from your db search # $ResultsPerPage $pages = PageSplit($ResultsPerPage,$TotalResults,"this_page.php?DB_Check=$DB_Result") ; # print the navigation echo $pages; -------- #here is the function that returns your navigation code function PageSplit($ResultsPerPage,$TotalResults,$link) { # need to pull in page in case you already requested one, may need $database global $page,$database; # first check to see if we need more than one page if (($TotalResults< $ResultsPerPage) || (!$page)) { $page = 0; $pages = "Pages: 1"; } # then process cases where we need more than 1 page if ($TotalResults> $ResultsPerPage) { $div = ceil($TotalResults/$ResultsPerPage); $temp = 0; $pages = "Pages: "; if ($page > 2) $temp = $page-2; if ($temp > 0) $pages .= "<a href=$link&page=0><< First Page</a> ... "; while ($temp < $div) { $temp2 = $temp+1; if ($temp == ($page+3)) { $temp = $div-1; $pages .= "... <a href=\"$link&page=$temp\">Last Page >></a>"; } elseif ($temp == $page) { $pages .= "$temp2 "; } else { $pages .= "<a href=\"$link&page=$temp\">$temp2</a> "; } $temp++; } } #dump our finished page code back to the variable return $pages; } -----Original Message----- From: jblythe@bold.binarylogic.com.au [mailto:jblythe@bold.binarylogic.com.au]On Behalf Of Joseph H Blythe Sent: Monday, December 04, 2000 5:20 PM To: PHP-General Subject: [PHP] Search Result Navigation Hello, I remember some time ago (I can't find the thread now) some discussion about making the navigational numbers at the bottom of a lot of search engines results pages fo example: Pages: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next >> can anyone point me to an example of how to do this with php/mysql, I already know how to do the next and previous stuff using the LIMIT statment of mysql but need some thoughts on how to make the right numbers for the amount of results in the query. Any ideas would be appreciated, Regards Joseph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#28670) next »