Join tables


i’d like to join 2 tables to show the users’ avatars from the table users and the comments from the table comments with this query :

SELECT users.avatar, users.user_name, comments.* 
FROM users, comments
WHERE users.user_name = comments.sender_uname AND = '$page'

but it returns the error :

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/path/comments.php  on line 21

I’m not a mysql expert but I found several tutorials and it doesn’t seem too complicated. And still I can’t figure out what is wrong with my query.
Any help is appreciated.

That’s why you should run your sql inside the database first and when it is working correctly only then add it to your front end application. Then you know any errors from that point are the front end’s problem.

Thank you guido! It was a collation difference between the tables! I hope I corrected the problem now.

It means the query hasn’t finished well. To see the mysql error, change

$result = mysql_query("your query is here");


$result = mysql_query("your query is here") or die ("mysql error : " . mysql_error());

Of course, since you didn’t post any code, I’ve guessed a bit. :slight_smile: