1

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)

4 Answers 4

3

Wouldn't GROUP Concat work?

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

Sign up to request clarification or add additional context in comments.

Comments

1

You can always use sub-select and pass it to IN() operator.

Comments

1

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

1 Comment

Thanks, the errors disappear but the actual script doesn't seem to do anything =( I used: $friendnotes = mysql_query("SELECT nid,user,subject,message FROM friendnote WHERE user IN ('SELECT u1,u2 FROM friends WHERE u1 = $userinfo[username] OR u2 = $userinfo[username]') ORDER BY timestamp ASC LIMIT 0,5"); When I try to use a MySQL function such as mysql_fetch_array() it doesn't return an error, but doesn't return any results either (and yeah I know theres entries in the database that matches the WHERE)
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.