PHP database search

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

PHP database search

Post 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
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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:
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

hmmmm
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post Reply