php links to search pages method
I am creating a program that will produce search results from a mysql database using php. The search will have 10 results per page. I am looking for methods that will create the links to different pages of the same search the very same was LinuxQuestions does in their forums. Here is the basic search code.
Thank you // the database is already open and // the database is selected function simple_search($searchType) { $query=mysql_query("SELECT * FROM item WHERE itemType='$searchType'"); //or die("(".mysql_errno().") Error:".mysql_error()); if(!$num_rows=mysql_num_rows($query)){ // see if there are any results print "<h2>Sorry there are no results from your search</h2>"; }else{ $num_rows=mysql_num_rows($query); //or die("(".mysql_errno().") Error:".mysql_error()); print "<h2>There are $num_rows results from your search</h2>"; get_page_string($num_rows); // here is where I want to call the function to get the string to link to the other pages print "<table width=\"100%\" align=\"center\" border=1>\n"; while($a_row=mysql_fetch_row($query)) { print "<tr>$a_row</tr>"; } print "</table><br>\n"; return; } } |
You usually just use an offset value - to get the number of pages just divide the total number of rows by 10. Then each link looks like:
<A href="search.php?search=word&page=1">1</A> <A href="search.php?search=word&page=2">2</A> Then in your code you print rows starting at "($page*10)-10" up to "$page*10". So page 2 would print matches 10 through to 19. |
That seems very easy. Hmm sometimes the answer is so obvious. I will post again if there is a problem.
|
All times are GMT -5. The time now is 12:21 PM. |