Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Notifications

Ok so maybe I am just blanking out here but I am making a notification system and I am using PHP as my backend. I am using the following code to set up the correct number of notifications

$updates = mysql_query("SELECT * FROM updates WHERE userid = '$uid'");
while($row = mysql_fetch_array( $query )) {
    if ($updates>0) {
        for ($i=0; $i<$updates;$i++) {
            echo '
                <li class="update">'.$updates.'</li>
            ';
         }
    } else {
        echo'<h4 class="nonew">No New Notifications</h4>';
    }
}

This code will echo the correct number of notifications but will echo the entire where it supposed to echo that single comments content. How do I echo only the contents of that single notification? I am sure this has a simple answer and I already know it but I just can't think of it right now. Thanks!


EDIT:

Heres my database structure:

Updates
-id
-userid
-active
-date
-content
like image 640
Joe Torraca Avatar asked Oct 08 '22 12:10

Joe Torraca


1 Answers

// In case $uid comes from user input
$uid = mysql_real_escape_string($uid);

// Fetch the user's notifications
$updates = mysql_query("SELECT content FROM updates WHERE userid = '" . $uid . "'");

if (mysql_num_rows($updates))
{
    // Output the user's notifications
    while ($get = mysql_fetch_array($updates))
    {
        echo '<li class="update">' . $get['content'] . '</li>' . "\n";
    }
}
else
{
    echo '<h4 class="nonew">No New Notifications</h4>' . "\n";
}
like image 120
Tom Avatar answered Oct 12 '22 11:10

Tom