steviez Posted January 29, 2008 Share Posted January 29, 2008 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 More sharing options...
Philip Posted January 29, 2008 Share Posted January 29, 2008 $query = "SELECT * FROM `comments` WHERE `userid`='".$userid."' && `read`='1'" Link to comment https://forums.phpfreaks.com/topic/88439-solved-help-with-comment-code/#findComment-452615 Share on other sites More sharing options...
steviez Posted January 29, 2008 Author Share Posted January 29, 2008 i need somthing to bring the alert up, like if there is comments in the database that are unread it will tell the users. Link to comment https://forums.phpfreaks.com/topic/88439-solved-help-with-comment-code/#findComment-452625 Share on other sites More sharing options...
Philip Posted January 29, 2008 Share Posted January 29, 2008 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 https://forums.phpfreaks.com/topic/88439-solved-help-with-comment-code/#findComment-452630 Share on other sites More sharing options...
steviez Posted January 29, 2008 Author Share Posted January 29, 2008 thanks for that but for some reason i cant get it to work :S Link to comment https://forums.phpfreaks.com/topic/88439-solved-help-with-comment-code/#findComment-452654 Share on other sites More sharing options...
Philip Posted January 29, 2008 Share Posted January 29, 2008 What errors come back? Link to comment https://forums.phpfreaks.com/topic/88439-solved-help-with-comment-code/#findComment-452657 Share on other sites More sharing options...
steviez Posted January 29, 2008 Author Share Posted January 29, 2008 none, thats the silly thing it just does nothing Link to comment https://forums.phpfreaks.com/topic/88439-solved-help-with-comment-code/#findComment-452661 Share on other sites More sharing options...
Philip Posted January 29, 2008 Share Posted January 29, 2008 <?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 https://forums.phpfreaks.com/topic/88439-solved-help-with-comment-code/#findComment-452664 Share on other sites More sharing options...
steviez Posted January 29, 2008 Author Share Posted January 29, 2008 Works perfect, thank you so much Link to comment https://forums.phpfreaks.com/topic/88439-solved-help-with-comment-code/#findComment-452682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.