How To Display Random Information From MySQL Database PHP Function

Mobile
feeds
Welcome Login | Register

How To Display Random Information From MySQL Database PHP Function
  Forums Index
      » MYSQL Forums
        » » How To Display Random Information From MySQL Database PHP Function



How To Display Random Information From MySQL Database PHP Function
Post Description:
Post Tags: how, to, display, random, information, from, mysql, database, php, function, mysql database, support, help, answers, questions, help
This Post Has Been Viewed 670 Times Since Tue Sep 05, 2006 7:21 am Posted By hostman with 0 replies
How To Display Random Information From MySQL Database PHP Function
Sometimes you want display random information from your database. I had a hardtime figuring out how to do is with php. I found the RAND() functions works greate with MySQL. Here I have create a snippet to help give you a sample code script:

The following example will display one output from your table. You can display multiple fields by doing a loop.

example: Make sure to provide your database information like your username, password, etc..


     Code:
<?
# Random Snippet Code Sample by http://www.wallpaperama.com
# 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];

?>


* make sure to edit the script and provide your correct table_name and field_name from your table, ( i used table_name and field_name as an example)


Leave Your Comments






Share
URL:
You can use this HTML code to put it on your website to show your friends this wallpaper. Use this code on your profile like myspace, friendster, Facebook or others. Just Copy and Paste it in your HTML on your websites



Fourms BBCODE:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums





Comments and replies About How To Display Random Information From MySQL Database PHP Function




(0) Comments