Hey all,

So I've avoided posting my question on this forum because it's kind of complex and there are a lot of moving pieces. However, I've tried everything I can think of and I think it's time I look for some direction from someone with a lot more experience than I have.

So I'm building a very basic social network website. This is mostly a project to get a good grasp on PHP/MySQL. Anyway, I have everything set up the way I want minus one thing...new photo upload notifications. So I'm using two different image files for the notification. One for when no new photos have been uploaded by a user's friend and one for when new photos HAVE been uploaded by a user's friend.

I've gotten really close several times. Now I'm able to get the notification image to show to everyone, friends and non-friends of the user, when the user uploads a photo. However, I want the notification to only show to friends of the user.

You'll probably first need to see the tables i'm using.

One table is for 'friends'. Rows are:
id, user1, user2, datemade, accepted (1 if yes, 0 if no)

Another table is for 'photos'. Rows are:
id, user, gallery, filename, description, uploaddate

Finally there is a table for 'users'. Only relevant rows for this issue are:
username, notescheck (updates to NOW everytime a user checks notifications)

So here is the code I've built to notify of photo uploads:

PHP Code:
    $sql "SELECT notescheck FROM users WHERE username='$log_username' LIMIT 1";
    
$query mysqli_query($db_conx$sql);
    
$row mysqli_fetch_row($query);
    
$sql "SELECT COUNT(id) FROM photos WHERE uploaddate > '$notescheck' AND user != '$log_username'";
    
$query mysqli_query($db_conx$sql);
    
$row mysqli_fetch_row($query);
    
$upload_count $row[0];
   if (
$upload_count != 0) {
       
$photo_note =  '<img src="images/photo_notification.jpg" width="22" height="12" alt="Notes">';    
   } else {
       
$photo_note =  '<img src="images/photo_NO_notification.jpg" width="22" height="12" alt="Notes">';        

        } 
So the issue I keep running into is I don't know how to make sure the notification ONLY goes to the user's friends. Obviously in the code above there is nothing filtering out 'only user friends' but here are some other things i tried that didn't work. When attempting the following code notifications wouldn't show at all:

PHP Code:
    $sql "SELECT notescheck FROM users WHERE username='$log_username' LIMIT 1";
    
$query mysqli_query($db_conx$sql);
    
$row mysqli_fetch_row($query);
    
$sql "SELECT user2 FROM friends WHERE user1='$log_username' AND accepted='1' LIMIT 1";
    
$query mysqli_query($db_conx$sql);
    
$row mysqli_fetch_row($query);
    
$sql "SELECT user FROM photos WHERE uploaddate > '$notescheck'";
    
$query mysqli_query($db_conx$sql);
    
$row mysqli_fetch_row($query);
    
$sql "SELECT COUNT(id) FROM photos WHERE uploaddate > '$notescheck' AND user='$user2'";
    
$query mysqli_query($db_conx$sql);
    
$row mysqli_fetch_row($query);
    
$upload_count $row[0];
   if (
$upload_count != 0) {
       
$photo_note =  '<img src="images/photo_flash.gif" width="22" height="12" alt="Notes">';    
   } else {
       
$photo_note =  '<img src="images/photo_still.jpg" width="22" height="12" alt="Notes">';        

        } 
Anyway...any help you'd be willing to give would be GREATLY appreciated. Thanks for taking the time to look over this.