Forum Moderators: coopster

Message Too Old, No Replies

mysql: Return a record that doesn't contain multiple values?

Will only accept the first value

         

whitenoise

10:48 pm on Feb 28, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi,

I am wondering if you people can help.

This code doesn't appear to work :


$q = 'SELECT ident, type, question, option1, option2, option3, option4, answer, stage
FROM data
WHERE type="test" AND ident!="'.$usedids.'"
ORDER BY RAND()
LIMIT 1';

Now $usedids is simply "125,54,56,36" etc. Basically I am trying to put together a quiz. Now I am trying to get it to select a random question from the database. The hard part comes is not showing that question again. Once a question is displayed I am storing it in an array. Each time a question is displayed it is being added to the array. What I am trying to get it to do, is every time it selects a question it should pick one in $usedids(which is now a comma sepreated string".

It seems to work for the first id, in this example 125. So once it has been displayed once the question with id 125 is not shown again - good. However it doesn't do this for the rest of the values in the string? Any idea why?

* In a nutshell I guess what I am trying to say is why can't I say the following. The first line works fine, but the second line doesn't?


Works :
WHERE type="test" AND ident!="123"

Doesn't work :
WHERE type="test" AND ident!="123,124,54,894"

?

Please help!

ergophobe

11:04 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try

WHERE type="test" AND ident NOT IN ('123','124','54','894')

whitenoise

9:54 am on Mar 1, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



Many thanks for that I will give it a try. I was trying all sorts to get it work! Cheers.