I am making a notification script and currently have this to display multiple notifications about the same image as one, e.g john likes image_name, sarah likes image_name -> 2 people like image_name.
this is what i have so far.
$query = mysql_query("SELECT type, extra_id, COUNT(*), id AS count FROM `notifications` WHERE `receiver_id` = '14' AND `read` = '0' GROUP BY type, extra_id");
while($row = mysql_fetch_array($query)){
if($row['count'] == 1){
switch ($row['type']) {
case "Following":
echo "John Doe is now following you <br />";
break;
case "Liked":
$image_id = $row['extra_id'];
$image_q = mysql_query("SELECT * FROM `images` WHERE `id` = '$image_id' LIMIT 1");
$image = mysql_fetch_array($image_q);
echo "John Doe likes ".$image['heading']."<br />";
break;
}
} else {
switch ($row['type']) {
case "Following":
echo $row['count']." New Users are following you <br />";
break;
case "Liked":
$image_id = $row['extra_id'];
$image_q = mysql_query("SELECT * FROM `images` WHERE `id` = '$image_id' LIMIT 1");
$image = mysql_fetch_array($image_q);
echo $row['count']." Users Like ".$image['heading']."<br />";
break;
}
}
}
And my database looks like this for notifications table.
http://i.minus.com/iZtrR0MNZ95Qn.png
And the output from the code is,
2 New Users are following you
5 Users Like IMAGE_ID_29
John Doe likes IMAGE_ID_50
where it should be
2 New Users are following you
John Doe likes IMAGE_ID_29
2 Users like IMAGE_ID_50
Your query currently is:
that is, your are using the
idfield as yourcount.You may probably want to rewrite it as: