orbitter Posted March 1, 2008 Share Posted March 1, 2008 hi there, if anyone can help, i am trying to produce a code using php to randomly output different peoples names (which are stored in a mysql database table) on a new page within the web browser every time a submit button is pressed. any help would be much appreciated. thank you Link to comment https://forums.phpfreaks.com/topic/93846-random-select-from-mysql-using-php/ Share on other sites More sharing options...
nano Posted March 1, 2008 Share Posted March 1, 2008 did u search? i am no php guru, but a from a simple search I found a few pages. http://www.learningmovabletype.com/a/001037random_quotes/ seems to be using the ORDER by rand() function when running a database query. hope this helps! Link to comment https://forums.phpfreaks.com/topic/93846-random-select-from-mysql-using-php/#findComment-480866 Share on other sites More sharing options...
beebum Posted March 1, 2008 Share Posted March 1, 2008 Look at MySQL's rand() function. http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand Link to comment https://forums.phpfreaks.com/topic/93846-random-select-from-mysql-using-php/#findComment-480878 Share on other sites More sharing options...
ILYAS415 Posted March 1, 2008 Share Posted March 1, 2008 hmmmm your code will be something lyk... <? $noobs= mysql_query("SELECT * FROM users ORDER BY RAND()"); $no_of_noobs= mysql_num_rows($noobs); if ($no_of_noobs == "0"){ echo "No noobs could be selected from the db"; }else{ $the= mysql_fetch_object($noobs); echo $the->username; } ?> you might have to change a few stuff accordingly to your database Link to comment https://forums.phpfreaks.com/topic/93846-random-select-from-mysql-using-php/#findComment-480897 Share on other sites More sharing options...
orbitter Posted March 1, 2008 Author Share Posted March 1, 2008 thank you so much guys, appreciate the help Link to comment https://forums.phpfreaks.com/topic/93846-random-select-from-mysql-using-php/#findComment-480906 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.