PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
echo "<b><u>Q u o t e s</u></b><BR><BR>";
$query = "SELECT firstname, lastname, pretext, text FROM quotes ORDER BY rand()";
$result = mysql_query($query) or die (mysql_error());
while($row = mysql_fetch_array($result)){
echo "{$row['firstname']} {$row['lastname']}, {$row['pretext']}<BR>"{$row['text']}"";
}
?>
MySQL Manual wrote:
From version 3.23 you can do: SELECT * FROM table_name ORDER BY RAND() This is useful to get a random sample of a set SELECT * FROM table1,table2 WHERE a=b AND c<d ORDER BY RAND() LIMIT 1000. Note that a RAND() in a WHERE clause will be re-evaluated every time the WHERE is executed. RAND() is not meant to be a perfect random generator, but instead a fast way to generate ad hoc random numbers that will be portable between platforms for the same MySQL version.
There is many ways to do this, but here is one I like...