I have a website with events, I got two important tables, one with all adresses for the first Newsletter and one for the registered users.
Now I want to send a Reminder to all adresses who doesn't register.
My idea is to compare the E-Mail Adresses from both tables (tbl_adresses and tbl_registered_usr) and "remove" all E-Mail Adresses which are in both tables.
My code looks like:
// Read records
$query = "SELECT email FROM wf_anlaesse WHERE anlaesseID = '$Datum'";
$query = mysql_query($query);
// Put them in array
for($i = 0; $array[$i] = mysql_fetch_assoc($query); $i++) ;
// Delete last empty one
array_pop($array);
print_r ($array);
echo "<br /><br /><br /><br />";
// Read records
$query2 = "SELECT email FROM wf_adressen";
$query2 = mysql_query($query2);
// Put them in array
for($i = 0; $array2[$i] = mysql_fetch_assoc($query2); $i++) ;
// Delete last empty one
array_pop($array2);
print_r ($array2);
echo "<br /><br /><br /><br />";
$result = array_diff($array, $array2);
print_r($result);
My output is like this:
Array (
[0] => Array ( [email] => E-MAIL )
[1] => Array ( [email] => E-MAIL )
[2] => Array ( [email] => E-MAIL )
[3] => Array ( [email] => E-MAIL ) ... and so on
Array (
[0] => Array ( [email] => E-MAIL )
[1] => Array ( [email] => E-MAIL )
[2] => Array ( [email] => E-MAIL )
[3] => Array ( [email] => E-MAIL )`... and so on
Array ( )
The array_diff doesn't do the trick.
Any ideas?
Thanks! Chris
mysql_queryshould not be used in new applications. It's a deprecated interface that's being removed from future versions of PHP. A modern replacement like PDO is not hard to learn and will make your database code easier to get right.