Jump to content


Photo

Help with INNER JOIN


  • Please log in to reply
4 replies to this topic

#1 stewart715

stewart715
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 21 October 2006 - 04:47 AM

ok i have a form where  person either selects privacy mode (which is a value of 1) or public mode (where it is a value of 2)..when submitted it is placed into a database called privacy mode with a column UID (which inputs the persons UID and a privacyid which inputs the selction they made.

I need a profile template to select that table based on that persons UID to see whether they chose 1 (which is private mode) or 2 (public mode)..if they chose 2..they can show the profile because its public mode but if they chose 1 i want the profile to check a 'buddylist' table to see if the person viewing has their user ID in the column 'buddy' next to the persons profile which their trying to viewings 'UID' (in the same row of course)

Example.. buddy PERSON A has a UID of 2..PERSON B has a UID of 4

PERSON A pics privacy so the table 'privacymode' has

UID  privacyid
2        1

PERSON B is trying to view PERSON A's profile so since PERSON A picked 1 for their privacyid the page checks buddy list for:

UID  buddy
2        4

In a nutshell:
i want it to do the query and then have it return a function if their is a relationship or if the privacyid is set to 2 (public mode)
else
return this function instead

I'm guessing I'd use INNER JOIN but how would i do this?

#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 21 October 2006 - 04:51 AM

I dont think you would need an inner join at all just add a privacyid column to your users table and a buddy list table and the php to handle them.
Why doesn't anyone ever say hi, hey, or whad up world?

#3 stewart715

stewart715
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 21 October 2006 - 04:54 AM

well, someone on this site told me to do this:

$sql = "SELECT p.*
        FROM profile p
        INNER JOIN privacymode pr ON p.UID = pr.UID
        LEFT JOIN buddylist b ON p.UID = b.UID AND b.buddy = '$userid'
        WHERE p.UID = '$profileid'
            AND ((b.UID IS NOT NULL) OR (pr.privacyid = 2) )";

which would work I think, however, I don't want it to pull the profile data from a table like it is..i want it to simply return a certain function if it's true and return a different function if false

in very very very ignorant terms lol:

$query = the above.

if true..
return function A

else

return function B

#4 stewart715

stewart715
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 21 October 2006 - 05:45 AM

Help :( Please

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 October 2006 - 08:15 PM

I don't know what you mean by "return a function" for DB query.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users