Jump to content

Archived

This topic is now archived and is closed to further replies.

davieboy

randomising a quote from mysql

Recommended Posts

what SELECT statement would i use to display a random quote taken from the database table??

 

Davi

Share this post


Link to post
Share on other sites

One way of doing that would be

 

like if have a unique ID to refer this quotes say u have 200 quotes and they have field say quote_id from 1 -200

 

u can use PHP rand() or srand() to select a number randomly and pass that to query.

Share this post


Link to post
Share on other sites

I agree 100% with what Shivabharat advised. A few things I would add though:

 

With the more current versions of php you suppossedly don\'t need to seed rand with srand.

 

I would select min(quoteid), max(quoteid) from yourtable first, then use those values to pass to rand:

 

$randid = rand($minval, $maxval);

 

Then as Shiv suggested just do a select quote from yourtable where quoteid = $randid

 

8)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.