Click to See Complete Forum and Search --> : Order MySql query by 2+ Fields


unl0ad
02-27-2007, 09:50 PM
Ok, im trying to arrange a Mysql query in php by 2+ fields

Lets say i have hour field, day field, month, and year field

I want to arrange by the newest posted to the oldest, heres what i have so far

query="SELECT `id1` FROM `".$mysql_prefix."images` WHERE `ban`!='yes' ORDER BY `day` DESC LIMIT $thumbnaillimit";

thanks in advance

NightShift58
02-28-2007, 12:32 AM
SELECT `id1`
FROM `{$mysql_prefix}images`
WHERE `ban` != 'yes'
ORDER BY `year` DESC, `month` DESC, `day` DESC, `hour` DESC
LIMIT $thumbnaillimit";

unl0ad
02-28-2007, 01:00 AM
thanks alot, now is there a way I can limit what comes out

Saying like show results 20-100 , would it be LIMIT 20-100?

mattyblah
02-28-2007, 01:12 PM
thanks alot, now is there a way I can limit what comes out

Saying like show results 20-100 , would it be LIMIT 20-100?

I think it would be LIMIT 20, 80
20 is the row offset, 80 is the number of rows

NightShift58
02-28-2007, 11:00 PM
To avoid confusion, use:

LIMIT $x OFFSET $y

which is the same as

LIMIT $y, $x