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

    }

}
?>

Recommended Answers

All 5 Replies

Cut your selected columns down to a specific set of columns then add the DISTINCT keyword to the appropriate column(s).

i.e.:
SELECT postId, DISTINCT userId, emailAddress, (etc...) FROM ......

Member Avatar for diafol

Ah, code blindness! Can't see the wood for the sequoias. What's your DB tables for this and what's stored in them?

You could use a "select distinct" in your sql queryso that every time a comment is made:

1) get poster id for the post (store that id in a var)
2) get commentors' ids for the post via 'select distinct' (get these where the user_id is not equal to the poster - don't want to duplicate).

You can either place all these ids into an array or string for later (single mail() with multiple bcc recipients) or 'firemail' them via the mysql_fetch_array loop.

//EDIT
sorry Fbody - simultaneous-ish post

@Fbody Thankx for the quick reply,DISTINCT is Wonderful.
The Notification is now working as needed.
@Ardav Thankx For ur suggestions.

Member Avatar for diafol

OK, thread solved?

sure solved)))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.