
December 19th, 2002
08:25 PM
Random Quote.
Howdy all - Just wondering how to genertae a random thing. I have summin like this....
<?
mysql_pconnect("localhost","","");
mysql_select_db("quotes");
if($submit)
{
$result=MYSQL_QUERY("INSERT INTO quotes (id,quotes)"."VALUES ('NULL','$quote','$id')");
}
?>
<?
$result = mysql_query("select * from quotes order by id desc limit 15");
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$quote=$r["quote"];
?>
<form action="<?=$PHP_SELF?>" method="post">
<INPUT TYPE='TEXT' value='quote' NAME='quote' SIZE=30 maxlength='100'>
I have that, it just adds quotes to a DB. how would i go about extracting random quotes and echoing them? Any help wopuld be helpful, cheers.
Last edited by -Karat, December 19th, 2002 08:57 PM (Edited 1 times)

December 19th, 2002
08:46 PM
mysql_query("SELECT * FROM tbl ORDER BY RAND() LIMIT 1");
___________________
[WebMobo] [Blog] [Me] [SFX]

December 19th, 2002
09:22 PM
with Mr. Jones
Status: Offline!
$result = mysql_query('select quote from quotes order by rand() limit 1');
Just a tad bit more efficient then psn... insignificant, really.
___________________
http://www.philbrodeur.com - Expert PHP Development and Tutorials

December 19th, 2002
09:30 PM
Yes, that 1 extra column is going to make quite a difference. 
___________________
Adam Goossens -- PHP is my mother tounge.
Linux: ( kernel.org | winehq ) -- f33l the p0w3r.
Nobody replying to your questions? Getting flamed? Getting told to RTFM? Ask your questions the right way.

December 19th, 2002
09:56 PM
Cheers for all the help, got it working. But when i add a quote, then refresh the page it resends the information. Any way i can stop this without having another page to handle the info?::classic:

December 19th, 2002
10:06 PM
with Mr. Jones
Status: Offline!
Yes, that 1 extra column is going to make quite a difference.
You could save almost a milisecond per every hundred billion requests! And we all love miliseconds!
___________________
http://www.philbrodeur.com - Expert PHP Development and Tutorials

December 19th, 2002
10:37 PM
Neverside Newbie
Status: Offline!
hmmm you could also load all of them up to an array and then use array_rand() but thats probably less efficient 
___________________
waveartists.com - design shop
devnet.waveartists.comDesign & Programming community
Current Projects: ChaosOps mod (HalfLife2)