Page 1 of 1
WHERE column IN (...) question.
Posted: Mon Aug 29, 2005 1:25 am
by s.dot
when using SQL like WHERE column IN (list here), does it only support integers in the list?
For example, can I do a query like
Code: Select all
$result = mysql_query("SELECT column FROM users WHERE username IN (username1,username2,username3)");
I have tried but it tells me
unknown column username1 in where claus
Posted: Mon Aug 29, 2005 1:29 am
by feyd
strings require quoting.....
Posted: Mon Aug 29, 2005 1:46 am
by s.dot
That makes sense. The error is gone, but there's no result now.
Code: Select all
$namelist = implode(",",$names);
$online = mysql_query("SELECT id FROM users WHERE username IN ('$namelist')") or die(mysql_error());
I've echo'd both, and everything appears to be correct. mysql_num_rows($online) returns 0
Posted: Mon Aug 29, 2005 2:00 am
by feyd
Code: Select all
$namelist = implode("','",$names);
Posted: Mon Aug 29, 2005 2:12 am
by s.dot
That's interesting.
Unless I have each name separated with ',' it treats the whole string as one long name?
Out of curiosity, why doesn't it do this with integers? Because they don't require quotes?
Posted: Mon Aug 29, 2005 7:06 am
by feyd
bingo.