Page 1 of 1

PHP database search

Posted: Mon Aug 23, 2004 8:27 pm
by davy2001
I know there is a way but it just isnt working!

I am trying to make a PHP script that searches a database and you can press "next page" and "previous page" and have a limit to 10 results per page.

So far i have:

Code: Select all

<?php

mysql_connect ('localhost', 'username', 'password') ;
mysql_select_db ('users');

$sql = "SELECT * FROM users ORDER BY id ASC LIMIT ".$limit.",10";

$result = mysql_query($sql) or
print ("Can't select entries from table php_blog.<br />" . $sql . "<br />" . mysql_error());

while ($row = mysql_fetch_array($result))
	&#123;
		$username = $row&#1111;"username"];
		$email = $row&#1111;"email"];
		$id = $row&#1111;"id"];

print "<table width=250 border=1 cellspacing=0 cellpadding=0>";
print "<tr>";
print "<td width=3>'$id'</td>";
print "<td width=247>'$username'</td>";
print "</tr>";
print "<tr>";
print "<td colspan=250>'$email'</td>";
print "</tr>";
print "</table><br><br>";
	&#125;

?>
<a href="users.php?limit=0,10">last 10 results</a>
<a href="users.php?limit=20,10">next 10 results</a>
:? :? :?

David

Posted: Mon Aug 23, 2004 8:32 pm
by tim
search this forum for 'pagination'

this topic has been discussed over 1000000000000x times (and clearly counting)

I think theres even a script in the code snipplets section, hint hint.

:twisted:

Posted: Mon Aug 23, 2004 8:33 pm
by davy2001
hmmmm

Posted: Mon Aug 23, 2004 8:37 pm
by feyd