Reputation: 27
I'm trying to query all results where surveyid contains my array $subscibearray. The problem is the SQL query is only returning the first result (44 in this case) instead of all of them. I tried using mysql_fetch_array as well without any success. My results are being outputted via Table. Any help would be appreciated. I omitted as much code as possible to make this easy to read.
Array format:
$subscribearray = "" . join(', ',$subscribearray) . "";
var_dump
of $subscribearray
:
string(17) "'44, 35, 194, 36'"
query:
$result = mysql_query("SELECT *
FROM surveys
WHERE surveyid IN ($subscribearray)
ORDER BY peercompletetime DESC
LIMIT 100")
or die(mysql_error());
Upvotes: 0
Views: 47
Reputation: 6016
You should:
$subscribearray = join(',', $subscribearray); // 1,2,3
Or:
$subscribearray = "'" . join("','", $subscribearray) . "'"; // '1','2','3'
If you wrap all ids with a string, it will look for the string, and not separated values. ('1,2,3')
Of course, if it's a numeric column you should use the first one.
Upvotes: 1