- Forums
- MYSQL
- How To Generate Random Tables Fields From MySQL PHP Function Snippet
This Page Contains information about How To Generate Random Tables Fields From MySQL PHP Function Snippet By misc in category MYSQL with 2 Replies. [2287], Last Updated: Mon Jun 24, 2024
misc
Fri Apr 25, 2008
2 Comments
654 Visits
if you want to generate random information from your mysql tables, all you have to do is use the RAND() function:
The following example will display one output from your table. You can display multiple fields by doing a loop.
example:
<?
# CONFIGURE
$db_host = 'localhost';
$db_username = 'myusername';
$db_password = 'mypassword';
$db_dbname = 'mydatabase_name';
# END CONFIGURE
$database = mysql_connect($db_host, $db_username, $db_password);
mysql_select_db($db_dbname,$db);
$sql = "SELECT * FROM table_name ORDER BY RAND()";
$result = mysql_query($sql ,$db);
$myrow = mysql_fetch_array($result);
echo $myrow[field_name];
?>