Jump to content

[SOLVED] Help with comment code


steviez

Recommended Posts

Hi,

 

on my site i have a comment box so users can send comments to one another. How can i make it so if there is a new comment a allert comes up in there account. All the info is stored in a database and unread comments are inserted with a read status or 0, then when read it turns to 1

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/88439-solved-help-with-comment-code/
Share on other sites

whoops, meant a 0 at read.

 

<?php
$query = "SELECT * FROM `comments` WHERE `userid`='".$userid."' && `read`='0'";
$select = mysql_query($query, $connection) or die(mysql_error());
$num_messages = mysql_num_rows($select);
if($num_messages > 0) {
echo "You have ".$num_messages." new messages!";
}
?>

 

Like that? If you want something live you need to go with AJAX, where if they get a message it will let them know without the user having to refresh the page

<?php
$query = "SELECT * FROM `comments` WHERE `userid`='".$userid."' && `read`='0'";
// Make sure to change fields/variables to match up with yours
$select = mysql_query($query, $connection) or die(mysql_error());
$num_messages = mysql_num_rows($select);
if($num_messages > 0) {
echo "You have ".$num_messages." new messages!";
} else {
echo "No new messages!";
}
?>

 

Try that. Make sure you have something in the database with read=0

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.