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
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

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.