Jump to content

Recommended Posts

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.

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?

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.

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.

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";
               }}

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

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

 

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-

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.

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.