Random quote from a database
This example will display a random quote from a MySQL database .
First create the database called quotes.

Now create our table quote with 3 fields called id , quote and author .

Now find some quotes and insert them into the table like this .

Now for the script .
<?php
//our connection details
$connection = mysql_connect("localhost" , "iainhendry" , "iain06");
//connect to quotes database using the $connection
$db = mysql_selectdb("quotes" , $connection);
//select all fields from image table
$sql_query = "SELECT * from quote";
$result = mysql_query($sql_query);
//find out the amount of rows
$getrowcount = mysql_num_rows($result);
//generate our random number between 1 and $getrowcount
srand(time());
$random = (rand()%$getrowcount + 1);
//sql query to retrieve an image where the id is equal to
//the random number $random
$fetchimage = "SELECT * FROM quote WHERE id = $random";
$result2 = mysql_query($fetchimage);
while ($rows = mysql_fetch_array($result2))
{
//build a table to put our quote
echo "<table>";
echo "<tr><td>";
//display the quote
echo "$rows[1]";
echo "</td></tr>";
//display author details
echo "<tr><td>";
echo "by : $rows[2]";
echo "</td></tr>";
echo "</table>";
}
?>