[thelist] Re: php mysql ORDER BY
Dunstan Orchard
dunstan at 1976design.com
Tue Jan 14 05:42:01 CST 2003
> rudy wrote:
>
> first, instead of entire rows, select just the primary keys randomly
>
> select id from $table
> order by rand() limit 5
>
> bring back those 5 ids into your php script, and stuff them into a second
> query which gets the rows in the order you want
>
> select * from $table
> where id in ( 45, 32, 87, 21, 55 )
> order by quizid
>
> easy, eh?
Thanks ever so much for that rudy, but I can't remember how to put the numbers
I've grabbed into the second statement.
// grab 5 random rows
$random = mysql_query("SELECT quizid FROM $table ORDER BY RAND() LIMIT 5",$db);
// grab data for those 5 rows
$display = mysql_query("SELECT * FROM $table WHERE quizid in (how do I get
those numbers in here?) ORDER BY quizid",$db);
Sorry, my brain seems to have gone on strike recently :o(
Thanks very much - dunstan
---------------------------
Dorset, England
http://www.1976design.com/
http://www.orchard.it/
http://www.maccaws.org/
More information about the thelist
mailing list