Forum Moderators: coopster

Message Too Old, No Replies

Spreading Searches Over pages

Query question

         

phidentity

10:48 pm on Jan 26, 2004 (gmt 0)

10+ Year Member



<?php global $db_list;

if($action == "search" )
{

$database = "nightlife_review";

$conn = @mysql_connect("localhost","user","pass")
or die ("Sorry");

@mysql_select_db($database) or die ("unable to select database!");

$query= "SELECT * FROM places WHERE name LIKE '%$Search%' LIMIT 0,5";

$result = mysql_query($query);

$num = mysql_numrows($result);
$num_results = $num/5;

echo("<p>Your Search Returned:</font></h1></p>");

$i=0;

while($i< $num){

$name=mysql_result($result,$i,"name");
$location=mysql_result($result,$i,"location");
$address=mysql_result($result,$i,"address");
$type=mysql_result($result,$i,"type");

$place_file_name = $location."/".$name.".php";

if( file_exists( $place_file_name ) )
{
echo("<tr><td><p><a href=\"$location/$name.php\">$name, $location, $type ($address)</a></p></tr></td>");
}
else { echo("<tr><td><p> $name, $location, $type (Does not have a Nightlife-Review Page)</p></tr></td>"); }

++$i;

}

}

?>

This works, but how would I do it, if I wanted 5 results per page, and then links to the rest of the pages (like google does).

So i'd have page 1,2,3,4,5 etc, and they;'d only display if there were enough results.

Be gentle, I'm new to this!

Cheers

Jon

[edited by: jatar_k at 11:08 pm (utc) on Jan. 26, 2004]

Timotheos

1:15 am on Jan 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've never done this before but there's alot of good examples if you Google for "php page numbering"

I'm sure the key here is the limit [mysql.com] on the end of the sql statement.