Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

75 users online



Random Quote.

Random Quote.

Currently viewing this thread: 1 (0 members and 1 guests)


-Karat

-Karat

Moomin
Status: Offline!

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)

psn

psn

Status: Offline!

mysql_query("SELECT * FROM tbl ORDER BY RAND() LIMIT 1");

___________________

[WebMobo] [Blog] [Me] [SFX]

Phil

Phil

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

Jeb

Jeb

Status: Offline!

Yes, that 1 extra column is going to make quite a difference. Tongue

___________________

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.

-Karat

-Karat

Moomin
Status: Offline!

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:

Phil

Phil

with Mr. Jones
Status: Offline!
Quote:


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

IceCube

IceCube

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 Tongue

___________________

waveartists.com - design shop
devnet.waveartists.comDesign & Programming community

Current Projects: ChaosOps mod (HalfLife2)

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0079 seconds.