Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking a smart notification list
    text
    copied!<p><strong>Scenario</strong> </p> <p>A image website that has basic features such as upload, comment, like, follow users etc.</p> <p>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 <code>notifications</code> table, and then has a <code>read</code> column which determines whether the user has seen it or not, simple.</p> <p>The current example output would be something like this,</p> <pre><code>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. </code></pre> <p>Which just basically is ordered by time of input.</p> <p>Now what i would like to achieve is something similar to the following,</p> <pre><code>4 users liked Picture of my cat. Henry Doe is now following you. </code></pre> <p>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.</p> <pre><code>$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']); } } </code></pre> <p>And then somehow sorting them to display correctly. But it still seems very complicated.</p> <p>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</p> <pre><code>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. </code></pre> <p>Into</p> <pre><code>2 People liked Picture of my cat. 2 New Users are now following you. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload