Re: Search Results - Next 10 records
| From: | Marcus Tobias | Date: | Mon, 03 Sep 2001 12:02:07 +0000 |
| Subject: | Re: Search Results - Next 10 records | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-12113@lists.php.net to get a copy of this message | ||
Hi Dennis!
You can add the parameter "LIMIT" to your SQL query.
Syntax: LIMIT $start_record,$record_count
Example: $query_string = "select * from $table where keywords like
'%$keyword%' limit 5,3";
This will return 3 records started with the 5. found record.
The startrecord has to increase on next page.
Store the current startrecord in the form and send it to the next page.
bye Marcus
"Dennis" <dennisb@unix.asb.com> schrieb im Newsbeitrag
news:20010903014505.81682.qmail@pb1.pair.com...
> Trying to figure out how to limit search results to say 10 records and
produce
> a button to show the next 10. Do you use PHP to do the logic, or should I
make
> another table column for a temporary count? This is what I'm up to so
far...
>
> Thanks in advance
>
>
> function show_all($table, $keyword=0)// initialize to zero
> {
global $start_record;
if ( !isset( $start_record ) ) $start_record = 0;
> $query_string = "select * from $table where keywords like '%$keyword%'";
$query_string = "select * from $table where keywords like '%$keyword%' limit
$start_record,10";
> $entire_table = mysql_query($query_string);
> $count = 0;
> print("<TABLE BORDER=1 width=700>\n");
> while ($cols_rows = mysql_fetch_array($entire_table)) {
> $count++;
> if ($count < 4){
> print("<tr>");
> print("<td bgcolor=azure>");
> print("<font size=3>");
> print ($cols_rows['num']);
> print("</td><td bgcolor=azure>");
> print("<font size=2>");
> print ($cols_rows['site_name']);
> print("</td><td bgcolor=azure>");
> print("<font size=2>");
> print ($cols_rows['keywords']);
> print("</td><td bgcolor=azure>");
> print("<font size=2>");
> print ($cols_rows['url']);
> print("<P></td>");
> }
>
> if ($count > 3){
> print("<tr>");
> print("<td bgcolor=silver>");
> print("<font size=3>");
> print ($cols_rows['num']);
> print("</td><td bgcolor=silver>");
> print("<font size=2>");
> print ($cols_rows['site_name']);
> print("</td><td bgcolor=silver>");
> print("<font size=2>");
> print ($cols_rows['keywords']);
> print("</td><td bgcolor=silver>");
> print("<font size=2>");
> print ($cols_rows['url']);
> print("</td>");
> $count++;
> }
> }
>
> print ("<FORM METHOD='POST' ACTION='search1.php'>");
print("<INPUT TYPE='text' NAME='start_record'
VALUE='$start_record+10'>");
> print ("<INPUT TYPE='submit' VALUE='Next'></FORM>");
> print $count;
> print("</TABLE>\n");
> }
>
>
> ?>
>