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 7816811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:00:37+00:00 2026-06-02T06:00:37+00:00

I want to store and retrieve user notification data for community site. The notifications

  • 0

I want to store and retrieve user notification data for community site. The notifications should be generated when someone comments on a user’s post or when someone follows’s a user. I want this behaviour to replicate Facebook notifications. So it should look like this:

User A, User B and 3 other started following you.
User A, User Z and 2 others commented on your post Super Duper.

If I create a generic array for holding the notifications then it would look like this:

$notification = array ($notification_id, notification_time, $read_status, $notification_recipient_id, $notification_initiator_id, $post_id=NULL, $comment_id=NULL); // This array represents a single notification

$notifications = array ($notification, ...); // This array is made up of many single notification array.

So, if I were to retrieve the data from $notifications array (the one containing all individual notification array), I would use a for loop and echo the results after sorting the array based on time. This would give me something like this as the result:

User A started following you.
User B started following you.
User C started following you.
User D started following you.
User E started following you.
User A commented on your post Super Duper.
User B commented on your post Super Duper.
User C commented on your post Super Duper.
User D commented on your post Super Duper.

So, if you look at the result I intend to achieve and the one that I would get out of the array design I currently have, both differ. I may be able to achieve the desired result by doing N number of operations that may involve flattening, recursive for loops, sorting, etc to the $notifications array. But, I think I could reduce the overhead by re-designing how the data is stored in the array so that when data needs to be retrieved I can perform least number of operations. Also, since read status needs to be taken into account while displaying data, it would even so more become complicated to achieve my desired result. I request for suggestions on designing the array structure and examples on how I could retrieve the data from the array to achieve the result I intend to.

  • 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-02T06:00:40+00:00Added an answer on June 2, 2026 at 6:00 am

    You could do the folowing:

    • select the notifications of type ‘following’, where read_status = ‘not_read’, LIMIT 2
    • count the notifications of type ‘following’
    • select the notifications of type ‘comment’, where read_status = ‘not_read’, LIMIT 2
    • count the notifications of type ‘comment’

    Whenever someone reads a notification, you set it to ‘read’.

    Whenever someone comments or follows something, you create a notification for all the related persons. Those persons are for example all the persons involved in a discussion, or just the person being replied to. Same thing for a comment.

    This way, you are able to format and display this message without manipulating too much data. (You can probably pack those requests for more efficiency, but you get the idea)

    User A, User B and 3 other started following you.
    User A, User Z and 2
    others commented on your post Super Duper.

    I would say that changing your data structure for a problem like this is overkill. With this approach, you would be constantly redefining your data model, which will soon become a nightmare. The data model should reflect the big constraints of your application, not ‘little” formatting problems like this one.

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

Sidebar

Related Questions

i want to store and retrieve data via the url hash. the user is
I am a new developer on Android and I want store user data in
In the event that you want to store user-dependent data in localStorage (e.g. because
I store some dates in my NSMutableArray, I want to retrieve them and change
I want to store profile details encrypted within a database. However, some details should
I want to store large chunks of data as JSON in the assets folder
I want to store the data returned by $_SERVER[REMOTE_ADDR] in PHP into a DB
Assuming I have an user who has an ID and I want to store
I want to store files uploaded by user in session variable,so that i can
I am creating a web application that lets the user store and retrieve information

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.