Reputation: 499
The implode() function works on normal arrays, but it doesn't work on arrays created with mysql_fetch_array (I also tried mysql_fetch_row)
How do you get them to work?
Defined Above:
$friends = mysql_query("SELECT * FROM friend
WHERE u1='$userinfo[username]' OR u2='$userinfo[username]' ");
And further down:
$friendsrow = mysql_fetch_array($friends);
$friendsrow = join(",",$friendsrow);
$friendnotes = mysql_query("SELECT nid,user,subject,message FROM friendnote WHERE user IN ($friendsrow) ORDER BY timestamp ASC LIMIT 0,5");
(In case your wondering, that is for a community site)
Upvotes: 1
Views: 6264
Reputation: 837
Wouldn't GROUP Concat work?
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
Upvotes: 3
Reputation: 33749
I think you're joining the wrong thing. You're joining the entire friend ROW, so the result is '1,Johnny,23years,etc'. I'm assuming you want a list of the friend ID's '1,2,3,4,5'. As Eimantas said it's better to use a subquery.
SELECT nid,user,subject,message
FROM friendnote
WHERE user IN ((SELECT u2 FROM friends WHERE u1 = $userinfo[username])
UNION
(SELECT u1 FROM friends WHERE u2 = $userinfo[username]))
ORDER BY timestamp ASC LIMIT 0,5
Upvotes: 1
Reputation: 1791
mysql_fetch_array returns normal arrays, there is nothing special about them. Maybe your query isn't returning anything, and in that case mysql_fetch_array returns false
. Check for that before trying to implode the result.
Upvotes: 0