query pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

query pages

Post 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...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I think you actually want:

Code: Select all

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