>From the German php FAQ:
version >= 3.23
SELECT * FROM tabelle ORDER BY RAND() LIMIT 1
version < 3.23
//see how many rows you have
$result = @mysql_query("SELECT COUNT(*) FROM $table");
$row = mysql_fetch_row($result);
//produce random number out of that
mt_srand((double)microtime()*1000000);
$number = mt_rand(0,$row[0]-1);
//fetch one record randomly
$result = @mysql_query("SELECT * FROM $table LIMIT $number,1");
Derick Dorner schrieb am Samstag, 21. Juli 2001, 05:33:13:
> ----- Original Message -----
> From: Derick Dorner
> To: [EMAIL PROTECTED]
> Sent: Tuesday, July 17, 2001 3:11 PM
> Subject: tricky RAND() function...
> I am using MySQL 3.22, and need to know how to randomly select a record, therefore I
>can't just use the ORDER BY RAND() clause, because of my version. so i do this:
> SELECT field1,field2*0+RAND() as rand_col FROM TableName WHERE field3=5 ORDER BY
>rand_col;
> --according to paul dubois' book I have to do that field2*0+rand to override mysql's
>query optimizer...?
> This works great randomly selecting records, but it obviously also returns the
>rand_col column, which I can't have (I have to output the data (a picture) straight
>into a web browser). How can I
> either re-write this statement or "hide" that rand_col column from showing up?
> all i want to do is randomly select one column using mysql 3.22, is this that hard?
> thanks in advance!
> -derick
--
Herzlich
Werner Stuerenburg
_________________________________________________
ISIS Verlag, Teut 3, D-32683 Barntrup-Alverdissen
Tel 0(049) 5224-997 407 · Fax 0(049) 5224-997 409
http://pferdezeitung.de
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php