View Full Version : php/mysql limit function, help
nobody
February 28th, 2005, 11:21 AM
Hey guys and gals.
I'm trying to pull the top two rows off of my mysql database through php, sorting by ID. I'm just having a sliiiight problem doing it. This is the code I'm using to query the database at the moment.
$query = mysql_query( " SELECT * FROM mainpage WHERE page = 1 ORDER BY ID DESC LIMIT 0 , 2 " );
binime
February 28th, 2005, 11:37 AM
Hey guys and gals.
I'm trying to pull the top two rows off of my mysql database through php, sorting by ID. I'm just having a sliiiight problem doing it. This is the code I'm using to query the database at the moment.
$query = mysql_query( " SELECT * FROM mainpage WHERE page = 1 ORDER BY ID DESC LIMIT 0 , 2 " );
$query = mysql_query( " SELECT * FROM mainpage WHERE page = 1 ORDER BY id DESC LIMIT 2 " );
SlowRoasted
February 28th, 2005, 11:39 AM
yeah what he said:)
Yeldarb
February 28th, 2005, 11:50 AM
Actually if you want the top 2, as in the first two, it would need to be:
$query = mysql_query("SELECT * FROM mainpage WHERE page=1 ORDER BY id ASC LIMIT 2");
nobody
February 28th, 2005, 11:54 AM
Thanks guys. I did that before but obviously I did something wrong because it gave me an error :P
Thank you:beam:
Voetsjoeba
February 28th, 2005, 02:01 PM
If I remember correctly, to select a range (for example 2,4) you need to put brackets around the numbers:
$query = mysql_query( " SELECT * FROM mainpage WHERE page = 1 ORDER BY ID DESC LIMIT (0,2) " );
But since 0,2 is the same as 2, just use LIMIT 2 as said above.
nobody
February 28th, 2005, 02:27 PM
Thanks voets :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.