Jump to content


Photo

queries.. to Join? and how?


  • Please log in to reply
2 replies to this topic

#1 craigeb78

craigeb78
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 March 2003 - 09:04 PM

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
if (session_is_registered(\'craigeb78\') { [br] click_banner(); [br] echo \"PHPFreaks rocks. Thanks for the help\"; [br] $knowledge++; [br]}

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 08 March 2003 - 09:12 PM

select a.* , b.*,c.* from user as a,physical as b,intrest as b where 



a.uid = b.uid = c.uid and a.id = $supplied_value;

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 craigeb78

craigeb78
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 March 2003 - 11:10 PM

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.
if (session_is_registered(\'craigeb78\') { [br] click_banner(); [br] echo \"PHPFreaks rocks. Thanks for the help\"; [br] $knowledge++; [br]}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users