deepson2 Posted June 29, 2009 Share Posted June 29, 2009 Hello, I wanted to build-up a module where if any user gets any shout/comment then send alert message to that user who has got this shout/comment.so when that users loggs in, he/she ll get this alert message.so he/she can see that message. I have done this through mail. but i just want to build up something like this. Can anyone tell me how can i do this? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/ Share on other sites More sharing options...
RussellReal Posted June 29, 2009 Share Posted June 29, 2009 if ($numOfPrivateMessages) echo "<script type='text/javascript'> alert('You have {$numOfPrivateMessages} new messages'); </script>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865455 Share on other sites More sharing options...
deepson2 Posted June 29, 2009 Author Share Posted June 29, 2009 f ($numOfPrivateMessages) how to count that? i mean, i have only table where i am storing only messages with id's. and secondly, i want to show this alert only once. could you please elaborate what you are trying to tell me? Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865463 Share on other sites More sharing options...
cunoodle2 Posted June 29, 2009 Share Posted June 29, 2009 Add a field to your table called status and set it to 1 when someone gets a new message. When each user loggs in check to see how many messages they have with a status level of 1. If they have none then do nothing if they have multiples then do a pop up box for them. After doing the pop up box and/or the user looks at the messages then set the status value of all of their messages to 0 so it won't come up again. Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865467 Share on other sites More sharing options...
deepson2 Posted June 29, 2009 Author Share Posted June 29, 2009 Thanks for your cunoodle2 , I am talking about here JS alert. if so then, After doing the pop up box and/or the user looks at the messages then set the status value of all of their messages to 0 so it won't come up again. Make sense? how can i check that? i mean if someone checked there message so i have to changed the status right? then how can i know that this message is seen now,just change the status now. please tell me. Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865470 Share on other sites More sharing options...
YourNameHere Posted June 29, 2009 Share Posted June 29, 2009 This is easily done with an IF statement in conjunction with a database. Make a hidden text field in your landing page that hold a value that is an echo from a database. This echo will be whether of not a new shout or comment was added to the DB. $comment = false; $container = $_POST['hiddenTextFieldToHoldData']; if (strtlen($container)>0){ $comment = true; } if ($container = true){ // echo markup for model dialog } Edit: To answer your question about knowing whether a message was seen or not, you need to make a seperate sql statement that changes the status to 0 using the UPDATE command. It is up to you how this is done and when, after they open the message, or after they check a checkbox or whatever. You just need to write the correct logic to make that happen. Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865473 Share on other sites More sharing options...
deepson2 Posted June 29, 2009 Author Share Posted June 29, 2009 see this is i am done with mail notification. $messagesql = $op->insert("INSERT INTO ".tbl_message." (toid,fromid,message,date) VALUES ('".$to."','".$from."','".$message."','".date('Y-m-d:h:i')."')"); if($messagesql > 0){ echo "SELECT a.username, a.fname as authorname, a.email, a.auth FROM ".tbl_author." a WHERE a.id='$to'"; $sql = $op->runsql("SELECT a.username, a.fname as authorname, a.email, a.auth FROM ".tbl_author." a WHERE a.id='$to'"); if(!$sql){ return false; } $row = $op->select($sql); $email = $row['email']; $fromemail = 'abc@xyx.in'; $mailbody .= "<p>Regards.</p>"; $mailbody .= "<b>Author's email:</b> ".$email."<br>"; $subject = "NEw message"; $fromemail = $fromemail; $to = $email; $msg = $mailbody; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; $headers .= "From:".$fromemail. "\r\n"; $headers; if(mail($to, $subject, $msg, $headers)){ echo "Mail has been sent Successfully."; } else { echo "Mail has not been sent Successfully.";} }else{ $err_msg_shout="Error, Try Again"; }} Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865474 Share on other sites More sharing options...
deepson2 Posted June 29, 2009 Author Share Posted June 29, 2009 Any Help??? Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865541 Share on other sites More sharing options...
deepson2 Posted June 29, 2009 Author Share Posted June 29, 2009 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <form name="messageFrm" action="<?$PHP_SELF;?>" method="post"> <script type="text/javascript"> var $check1 = <?=$check?>; if($check1 == 'Y') { alert ("You have an unread message"); } else { document.write (""); } </script> </head> <?if(!$userid){?> <body id="free"> <?}else{ ?> <body> <?}?> <? //this record is exist in database echo "SELECT * FROM comments where userid='$userid' and blogid='11072'"; $result = mysql_query("SELECT * FROM comments where userid='88' and blogid='11072'"); if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)) { $check= $row['chkstatus']; }} ?> </form> </body> </html> I have tried this. just to check whether i am getting alert message or not. no luck. any one can tell me how can i get alert message here? Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865603 Share on other sites More sharing options...
YourNameHere Posted June 29, 2009 Share Posted June 29, 2009 For a script like that to work, it must be echoed. You cant just mix the two languages together like that. And remember to to do linebreaks otherwise you would be left with a gient line of generated php code that would be unreadable in the end. I.e /n /r Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865763 Share on other sites More sharing options...
RussellReal Posted June 29, 2009 Share Posted June 29, 2009 YourNameHere, you are barking him up the wrong tree.. my post gives him the correct answer, all he needs to do is fill $numOfPrivateMessages with THE NUMBER OF TOTAL PRIVATE MESSAGES WHICH R NEW.. and the if statement should work.. and echo the html and the alert fine- Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-865934 Share on other sites More sharing options...
deepson2 Posted June 30, 2009 Author Share Posted June 30, 2009 On index.php PHP Code: <?php echo "SELECT c.comment, c.blogid, c.chkstatus FROM comments AS c, bloginfo AS b WHERE c.blogid = b.id AND b.author = '$userid' AND c.chkstatus = 'N'"; $result = mysql_query("SELECT c.comment, c.blogid, c.chkstatus FROM comments AS c, bloginfo AS b WHERE c.blogid = b.id AND b.author = '$userid' AND c.chkstatus = 'N'"); if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)) { $check= $row['chkstatus']; if ($row['chkstatus']=='N') { ?> <script type="text/javascript"> alert('You have unread comments.'); </script> <?php } }} ?> and then on blogprofile.php PHP Code: <? echo "Update ".tbl_comments." Set chkstatus = 'Y' where blogid='$blogid'"; $sSqlSec = $op->runsql("Update ".tbl_comments." Set chkstatus = 'Y' where blogid='$blogdata->blogid'"); ?> With these query i am able to show alerts and then once user checks his/her blog's comment then status changes from 'N' to 'Y'. No the issue is redirection. when i logged in if i have comment on my blog then firstly my index page goes blank with only alert message. and when i click on ok then it goes to its index page. how can i get index page as well as this alert message at time? please help me. Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-866252 Share on other sites More sharing options...
deepson2 Posted July 1, 2009 Author Share Posted July 1, 2009 Any Help?? Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-866891 Share on other sites More sharing options...
joel24 Posted July 1, 2009 Share Posted July 1, 2009 use the window.onload function, so it only executes once the page is loaded. <script type="text/javascript"> window.onload = function() { alert('You have unread comments.'); }; </script> Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-866893 Share on other sites More sharing options...
deepson2 Posted July 1, 2009 Author Share Posted July 1, 2009 dialog box is my solution http://jqueryui.com/demos/dialog/ It sorted out now. Quote Link to comment https://forums.phpfreaks.com/topic/164059-solved-alert-notification-that-users-got-new-message/#findComment-866946 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.