Hi there folks 😃
I dont know how exactly to use left join but i think that its the solution for my problem.. here´s what i got:
I m using the Invision Power Board Database (forum database) with some custom tables in my website... and i have 3 tables:
1 - Comments table (id,username,comment,date)
2 - ibf_members table (id,name)
3 - ibf_member_extra (id,avatar,signature)
But the real problem is that:
Comments store the comments of course but i m using the user name in the table.. not the user id
i have to acess the ibf_members table to get the user id and then use the user id to get the avatar data on the ibf_member_extra table... i ve made it work.. but in the wrong way.. now i want to make it with less querys 😛
Here´s what i got:
<?
//this is my comments query:
$coment_query ="SELECT comentarios.*,ibf_members.id, ibf_members.name
FROM comentarios, ibf_members
WHERE comentarios.demo_id=$id AND comentarios.usuario=ibf_members.name
ORDER BY data ASC";
// this is my members query (to get the id)
$members_query = "SELECT ibf_members.id,ibf_members.name
FROM ibf_members
WHERE ibf_members.name='$avatar_user'";
//And this is my avatar query
$member_avatar_query = "SELECT ibf_member_extra.avatar_location, ibf_member_extra.avatar_type, ibf_member_extra.signature
FROM ibf_member_extra
WHERE ibf_member_extra.id=$avatar_user_id";
?>
I m using the last 2 querys inside a loop, so if i have 20 comments.. its gonna be 20 querys :eek:
and its completly wrong.. please anyone can help me to me it with less querys as possible?
Thanx in advance