Jump to content

help joining table


corillo181

Recommended Posts

hey i want to select 3 tables,

in one table i have some info about the user such as a username,

the next table i have personal information about that user such as name ect.

that last table i have photos of that user..

 

i did a query as this

SELECT w.usename, i.name, p.path FROM user w, user_info i, photos p, WHERE w.id = i.id AND w.id = p.id

 

this works fine, but if the user has more then one picture the user info show twice.

 

i try using DISTINCT but it didn't work.

 

any help? thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/106278-help-joining-table/
Share on other sites

I think you join the first two table user and user_info and get id then use photo table with DISTINCT pass id in where

 

like

 

$sql="SELECT w.id as id,w.usename, i.name, p.path FROM user w, user_info i, WHERE w.id = i.id ";

$query=mysql_query($sql,$link);

while($row=mysql_fetch_array($query)){

$id=$row[id];

$sql2="select DISTINCT id, path from photos where id=$id";

echo the result

}

 

may this idea help you

Link to comment
https://forums.phpfreaks.com/topic/106278-help-joining-table/#findComment-544676
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.