/    Sign up×
Community /Pin to ProfileBookmark

How to set up ‘photo upload’ notification

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 ‘[B]friends[/B]‘. Rows are:
[B]id, user1, user2, datemade, accepted[/B] (1 if yes, 0 if no)

Another table is for ‘[B]photos[/B]‘. Rows are:
[B]id, user, gallery, filename, description, uploaddate[/B]

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

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

[code=php] $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”>’;

} [/code]

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:

[code=php] $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”>’;

}[/code]

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

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @froppo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...