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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.