[sovled] Complex database selection
Posted: Sun Aug 07, 2005 9:50 pm
I'm writing a script to display one quiz item to a user at a time, the items will be displayed in a random order and the same item will not be displayed twice, I was wondering the best way to select a random question given that I have an array of questions that have already been selected, should I loop through the array building a huge WHERE clause? Would it be possible to have a table named `viewed` that has has a user id column, then do something like (dont even know if this is valid mySQL or not):
Are there any other options on the table? Thanks for your input.
Code: Select all
SELECT FROM `questions` ORDER BY rand() WHERE `id` != (SELECT `id` FROM `viewed` WHERE `user` = '$user') LIMIT 1 ;