davieboy Posted June 9, 2003 Share Posted June 9, 2003 what SELECT statement would i use to display a random quote taken from the database table?? Davi Quote Link to comment https://forums.phpfreaks.com/topic/564-randomising-a-quote-from-mysql/ Share on other sites More sharing options...
shivabharat Posted June 9, 2003 Share Posted June 9, 2003 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. Quote Link to comment https://forums.phpfreaks.com/topic/564-randomising-a-quote-from-mysql/#findComment-1894 Share on other sites More sharing options...
gizmola Posted June 9, 2003 Share Posted June 9, 2003 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 Quote Link to comment https://forums.phpfreaks.com/topic/564-randomising-a-quote-from-mysql/#findComment-1896 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.