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 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. 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 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
Archived
This topic is now archived and is closed to further replies.