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 Quote 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'" Quote 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. Quote 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 Quote 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 Quote 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? Quote 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 Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.