i have a web in which after member login, is able to publish blog post and only logged in members can comment.
Now my problem comes in notification.
1.I need after someone comment then to send notification to the owner of the post.
2.Also if other members commented on the same post they have to be notified.(someone commented a post which u also commented).
MY PROBLEM IS IN THE SECOND PART,that if someother people commented and he/she commented more than one then the notification goes as many times as he/she commented.
And i want to Avoid that...HElp please. Down is my script
<?php session_start();
$email=$_SESSION['email'];
$name=$_SESSION['name'];
$loggedid=$_SESSION['id'];//login id
include"config.php";//connecting to db
if(isset($_POST['submit'])){
$comment=$_POST["comment"];
$senderid=$_POST["senderid"];//senderid id
$postid=$_POST["postid"]; //post id
//insert the comments into the database
$query = "INSERT INTO postcomment SET comment='$comment',posterid='$userid',postid='$po'" ;
$result=mysql_query($query);
//check to see comment inserted successfully to the db
if($result) {
//select email of the owner of post
$dd=mysql_query("SELECT email FROM member WHERE id='$senderid'");
$ss=mysql_fetch_array($dd);
$menyepichaemail=$ss['email'];
//send notification to the user
$from="From:myweb@myweb.com\r\n";
$to="$menyepichaemail";
$subject="$name Commented Your post";
$content="$name Commented Your post, to see the comment click link below \r\n http://myweb.com/postview.php?contid=$po";
if($content){
mail($to, $subject, $content,$from);
}
/* CHECK TO SEE OTHER PEOPLE ALSO COMMENTED,EXCLUDING LOGGEDID AND OWNER OF THE POSTER
IF SOMEOTHER PEOPLE COMMENTED THEN TELL someone commented a post that u also commented.
SOMEONE COMMENTED MORE THAN ONCE THEN SEND ONE NOTIFICATION
HERE IS WHERE I DONT KNOW HOW STOP SENDING NOTIFICATION MORE THAN ONCE
*/
$check=mysql_query("SELECT *FROM postcomment WHERE ((postid='$postid') and ((posterid!='$senderid')or(posterid!='$loggedid'))");
$count=mysql_num_rows($check);
if($count>0){
while($row=mysql_fetch_array($check)){
$commenterid=$row['posterid'];
//select the email of the person who also commented
$query=mysql_query("SELECT email FROM member WHERE id='$commenterid'");
$rr=mysql_fetch_array($dd);
$com_email=$rr['email'];
//then send notification
$from="From:myweb@myweb.com\r\n";
$to="$com_email";
$subject="$name Commented post that u also commented";
$content="$name Commented post that u also commented, to see the comment click link below \r\n http://myweb.com/postview.php?contid=$po";
if($content){
mail($to, $subject, $content,$from);
}
}
}
}
}
?>