Duplicate find and separate.....! please help me.

Discussion in 'PHP' started by strgraphics, Jun 20, 2010.

  1. #1
    I am doing email adding program into my database..!

    in that some code"

    <?php
    
    
    $email=$_POST['email'];
    
    $datetime=date("d/m/y h:i:s"); //create date time
    
    
    
    
    $status1 = "OK";
    $msg1="";
    
    
    if(strlen($email) <=0){
    $msg1=$msg1."E-mail/E-mail Row You Entered Should Not Be Empty <br>
    Make sure that there is no spaces <br><br>";
    $status1 = "NOTOK";}
    
    
    
    if($status1<>"OK")
    {
    echo "<font face='Verdana' size='2' color=red>$msg1</font>";
    }
    
    
    
    if($status1 == "OK")
    {
    
    $email_addresses = "$email";
    $sql = "insert into $tbl_name (email) values('". join("'), ('", preg_split('/\s*,\s*/', $email_addresses)). "')";
    
    
    // $sql="INSERT INTO $tbl_name(email)VALUES('$email')";
    $result=mysql_query($sql);
    }
    
    if($result){
    ?>
    PHP:
    This will adds multiple emails with comma, so yester day i tried to add 186 emails at a time.. alll are added but my problem is of which some are already there..


    What i need is: when i press add, in my form
    it must check the email is there in the database and separate those and echo them...

    Example:
    i mean.., i need to print out of 186, let 56 mails are add and 130 are duplicate message with the mails too

    Hope you understand please help me..


    thanksssssssssssssssssss a lottt.!
     
    strgraphics, Jun 20, 2010 IP
  2. ZeeshanButt

    ZeeshanButt Well-Known Member

    Messages:
    307
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #2
    select existing emails and in loop, compare them and print out is duplicate.
     
    ZeeshanButt, Jun 20, 2010 IP
  3. TsubasaOzora

    TsubasaOzora Well-Known Member

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    113
    #3
    or u can use count(email) query on your sql...
     
    TsubasaOzora, Jun 20, 2010 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #4
    You might find the "on duplicate" option useful

    http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

    however if it seems advanced I'd just explode the string of emails, work through them one by and check to see if they have already been added. Depending on the size of your list you may be better to query over and over, or get the lot into an array and check the array.
     
    sarahk, Jun 20, 2010 IP
  5. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    ya i think better to check by taking into array..! i will try.

    Still any body have better idea.....!,

    when i click on submit button with 200 emails, the corresponding page will....

    
    
    $email=$_POST['email'];
    
    hear as i submitt 200 emails..
    
    echo "$email";
    
    This will prints email1, email2, email3, email4, email5....................email199,email200.
    
    But how can i take into array one by one.., any body please give me as a simple script lines.. not just like comments..
    
    
    PHP:

    Thanks for your replies friends..!

    ----------------------------------------------------------------------------------------------

    And

    
    $c = join("'), ('", preg_split('/\s*,\s*/', $email));
    
    
    PHP:
    this above line printing..., email1'),('email2'),('email3'),('email4'),('email5'),('email6'),..................('email200'),

    how can i take them in to array so that i can check easily...,
     
    Last edited: Jun 21, 2010
    strgraphics, Jun 21, 2010 IP