Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8420597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:55:04+00:00 2026-06-10T02:55:04+00:00

Scenario A image website that has basic features such as upload, comment, like, follow

  • 0

Scenario

A image website that has basic features such as upload, comment, like, follow users etc.

Now i have a basic notification system that i built very quickly which just basically when a event happens such as an upload or like it is inserted into the notifications table, and then has a read column which determines whether the user has seen it or not, simple.

The current example output would be something like this,

John Doe liked Picture of my cat.
Sarah Doe liked Picture of my cat.
Adam Doe liked Picture of my cat.
Sarah Doe liked Picture of my cat.
Henry Doe is now following you.

Which just basically is ordered by time of input.

Now what i would like to achieve is something similar to the following,

4 users liked Picture of my cat.
Henry Doe is now following you.

I am trying hard to wrap my average PHP knowledge around this and the best way i can think of is doing something like this.

$query = mysql_query("SELECT * FROM `notifications` WHERE `read` = '0' LIMIT 20");
$likes = array();
$following = array();
while($row = mysql_fetch_array($query)){

    if($row['type'] == "like"){

        array_push($likes,$row['id']);

    }   elseif($row['type'] == "following"){

        array_push($following,$row['id']);

    }

}

And then somehow sorting them to display correctly. But it still seems very complicated.

Also one more thing to think about if anyone comes up with a suggestion, would it be a good idea to have a algorithm in place that would group them even if they are not directly after each other, for example 5 minutes apart but with different notifications in between, for example

John Doe liked Picture of my cat.
John Doe is now following you.
Sarah Doe liked Picture of my cat.
Sarah is now following you.

Into

2 People liked Picture of my cat.
2 New Users are now following you.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:55:05+00:00Added an answer on June 10, 2026 at 2:55 am

    i believe the best solution is using GROUP BY in SQL not at PHP side. You need to group the results by the event type. If there is a single result, just show the single result by using a second query. If there are more than one results, just show COUNT(*) as you intended.

    EDIT: Examples.

    SELECT event_type, COUNT(*) AS count FROM `notifications` WHERE `read` = '0' GROUP BY event_type
    
    result:
    event_type  count
    ----------  -----
    4           4
    6           2
    9           1
    12          2
    

    Then you may run second queries for the events which are only appeared once.

    SELECT * FROM `notifications` WHERE `read` = '0' AND `event_type` = '9'
    

    of course you should also change their read status at the end

    UPDATE `notifications` SET `read` = '1' WHERE `read` = '0'
    

    These are just fast prepared examples. You should take care of special cases, updating only shown entries etc.

    I used event_type as a field. I believe you have a field like this. You should rename that part according to your database structure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scenario where users can upload an image, OR a video (from
I want to show image in a crystal report. Scenario is something like this.
Im looking for upload and crop image in PHP. The scenario is: user choose
Scenario: I have a directory on a server that hosts my website that contains
Scenario: I have SVG image that I can zoom-in and zoom-out. Depending on the
I have a Scenario that validates that the image I just uploaded exists on
The scenario is: when a user upload a image, we do image resizing on
We have scenario of image upload in ASP.NET MVC3. Controller public ActionResult Upload(IEnumerable<HttpPostedFileBase> images,
Scenario I have a Node.JS service (written using ExpressJS ) that accepts image uploads
I have a scenario where I have an image property that is part of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.