Jump to content

queries.. to Join? and how?


craigeb78

Recommended Posts

I hope somebody will understand what I\'m asking and will be kind enough to give a response.

 

Basically, lets say I have 3 tables, all containing information about users...

 

user table:

 

uid name lname

1 john fanny

 

physical table:

 

uid sex eye_color

1 1 4

 

interest table:

 

uid hobbies preferences

1 text text

 

(also have tables with color id\'s and sex id\'s but I guess it\'s not important at this point)

 

What i\'m trying to do is a search via php where it will query the the physical table for the specified sex, obtain all those rows for uid, and then output information from the interest, physical and user table for each uid returned.

 

I think i\'ve been staring at this stuff too long, and I\'m just lost.

 

Anybody have any ideas where I can start? You\'re guidance on this would be greatly appreciated.

 

-Craig

Link to comment
https://forums.phpfreaks.com/topic/206-queries-to-join-and-how/
Share on other sites

Thanks for the help on that. I think that will work eventually.

 

I am having trouble though.. I guess its more complicated than i originally let on.

 

The way I\'m trying to do it now, is the form is searching the profile table for sex and returning all uid\'s that match that sex:

 


$sql = mysql_query("SELECT uid FROM profile WHERE sex=$sex")



//Putting result to array



while($uidarray = mysql_fetch_array($sql)

{

$uid = $uidarray[uid];



//then attempting to retrieve all infomation from 3 tables as you have showed me



$sql2 = ("SELECT a.*, b.*, c.* FROM user AS a, profile AS b, interest AS c WHERE a.uid = b.uid = c.uid and a.uid=$uid");



//putting all returns into array  (i\'m not sure if this is right)



$result = mysql_fetch_array($sql2);



$username = $result[username];



echo "$username";



}



 

I\'m not sure of the best way to do what I\'m trying to do above, but $username isnt returning any value in this instance.

 

Can ya tell me if the above should work or the best way to do it?

 

Thanks a ton.

Link to comment
https://forums.phpfreaks.com/topic/206-queries-to-join-and-how/#findComment-623
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.