Hello, I have a progam that keeps track of addresses. The client can add addresses 1 at a time or enter entire lists at a time.
I am wondering what is the best/fastest/most proficient way to check If that email address is already in the db and if so not add it.
For example I have all of these email addresses in an array $EmailAddys[]
Now I do a for each loop to add them to the db like so
$NumItems=Count($EmailAddys);
For ($Counter=0; $Counter<$NumItems; $Counter++){
$Sql = "INSERT INTO tblEmailInfo (EmailAddress, ListName,Active) VALUES ('$EmailAddys[$Counter]','$ListName','TRUE')";
$Result = mysql_query($Sql,$Connect);
}
Now, Should I do individual Select statements before adding each address like so
$NumItems=Count($EmailAddys);
For ($Counter=0; $Counter<$NumItems; $Counter++){
$Sql = "SELECT * FROM tblEmailInfo WHERE EmailAddress = '$EmailAddys[$Counter]'";
$Result = mysql_query($Sql,$Connect);
$NumRows=mysql_num_rows($Result);
If($NumRows >0){
$Sql = "INSERT INTO tblEmailInfo (EmailAddress, ListName,Active) VALUES ('$EmailAddys[$Counter]','$ListName','TRUE')";
$Result = mysql_query($Sql,$Connect);
}
}
Or should I do a select statement and get every email address and put them in an array and then compare the 2 arrays and remove all the duplicates from my new addresses array that im about to add? If so then what is the best way to do that?
Thanks!😃