Jump to content


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


Comparing MySQL Database Tables

Recommended Posts

I'm developing a privacy feature based on the following:
The person selects either private mode or public mode..if they select private mode, the value of 1 is inserted into a table.  if they select public mode..the value of 2 is inserted (along with their UID)..that part i already did

this is what im having trouble figuring out doing..

then i want the profile page to select that table based on that persons UID to see whether they chose 1 or 2..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 Mike has a UID of 2..buddy Joe has a UID of 4

Mike pics privacy so the table privac mode has

UID  privacyid
2        1

Joe's trying to view mikes profile so since mike picked 1 the page checks buddy list for:

UID  buddy
2        4

if it's not there..then it wont show


Share this post

Link to post
Share on other sites
This query should do it

$profileid = 2;  // mike
$userid = 4;  // joe

$sql = "SELECT p.*
        FROM profile p
        INNER JOIN privac 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) )";

returns profile data if buddy rec exists or profile is public

Share this post

Link to post
Share on other sites
I have a php template of the profile, which is where I wanted to place this code... I can't have it pull the profile data from the database..

so if the person is a friend or it is public,it shows the following html..if it is private and theyre not friends..it shows this html instead..how do i do that?

Share this post

Link to post
Share on other sites

$res = mysql_query($sql) or die (mysql_error());

if (mysql_num_rows($res) == 0 {

      // cannot view profile
else {

      // show profile

Share this post

Link to post
Share on other sites


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.