Forums »
  MySQL Forums And Topics Discussions About Open Source Database »
    How To Display Random Information From MySQL Database PHP Function

How To Display Random Information From MySQL Database PHP Function

Description: How To Display Random Information From MySQL Database PHP Function
Tags: how ,to ,display ,random ,information ,from ,mysql ,database ,php ,function
Posted On Tue Sep 05, 2006 By hostman In MySQL Forums And Topics Discussions About Open Source Database Forums
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)
Information
Title: How To Display Random Information From MySQL Database PHP Function
Info: This Post Has Been Viewed 0 Times Since
Date: Tue Sep 05, 2006
Author hostman Received 0 Replies #858
Related Content
Related Pages
Related Sites
Add Your Website
Share
wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Wed Jun 19, 2013 (-8 GMT)
Powered by: Webune Forums V5