pluginbaby Posted August 23, 2006 Share Posted August 23, 2006 I got a question:Imagine this table:id | number1 | 12 | 23 | 34 | 25 | 6now I make a select in php:$str = "select id from table X where number=2 limit 1";$result=mysql_query($str) or die (mysql_error());$line = mysql_fetch_row ($result);$id = $line[0];when I do this, the database selects the first possible id where the number=2.What I want to do is make the database select a random id where the number=2.So it would response with id = 2 sometimes, and other times with id = 4Is this possible? Link to comment https://forums.phpfreaks.com/topic/18450-mysql-select-command/ Share on other sites More sharing options...
fenway Posted August 23, 2006 Share Posted August 23, 2006 Sure... add an ORDER BY RAND() before the LIMIT clause. Link to comment https://forums.phpfreaks.com/topic/18450-mysql-select-command/#findComment-79368 Share on other sites More sharing options...
pluginbaby Posted August 23, 2006 Author Share Posted August 23, 2006 thank you, I appreciate your help, it works perfectly now ;D Link to comment https://forums.phpfreaks.com/topic/18450-mysql-select-command/#findComment-79387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.