Page 1 of 1

query pages

Posted: Wed May 03, 2006 12:47 pm
by elecktricity
well ive recently been making a 'page' system on my thing, basicialy works like this:

Code: Select all

<?PHP
//pages.php?page=2
$page = ereg_replace('[^0-9]', '', $_GET['page']); //get page number
$page *= 10; //multiple by 10 to get result id's correct
$result = mysql_query("SELECT name FROM search WHERE id>='$page' LIMIT 10");
echo '<hr>';
while($row=mysql_fetch_assoc($result)) {
	echo $row['name'];
	echo '<hr>';
}?>
this worked fine but I wanted it ordered differently, it was displaying the older ones first so I changed the query to:

Code: Select all

SELECT name FROM search WHERE id>='$start' ORDER by id DESC LIMIT 10
which works fine on the first page but the second page it starts with the last added when it should be the first...

Posted: Wed May 03, 2006 1:59 pm
by Christopher
I think you actually want:

Code: Select all

$result = mysql_query("SELECT name FROM search LIMIT $page,10");