Thanks in advance for anyone who can help me with this query.
I want to select all from table one and the matching image from table two.
Using the following inner join query works great:
$result=mysql_query("SELECT *
FROM members inner join avatars
on members.user_id=avatars.user_id
where members.user_id ='{$user_id}'");
but if there is no corresponding record on avatars I get a broken result, so I want to retrieve a default avatar. (avatar_id=1)
so essentially what I am trying to do is two queries with an 'if' statement.
$result=mysql_query("SELECT * FROM members
inner join avatars on members.user_id = avatars.user_id
where members.user_id ='{$user_id}'");
if (mysql_num_rows($result)==0)
//how do I join these two queries so it retrieves all the correct info from the //Members table and the default avatar from the avatar table?
$result= mysql_query("SELECT * FROM members
where user_id ='{$user_id}' ");
$result=mysql_query("SELECT * from avatars where avatar_id=1");
}
while ($row = mysql_fetch_assoc($result)){
echo "
any help is greatly appreciated.