Forum Moderators: mack
<?php
include("config.php");
Connect to the database server
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database $DBName");
mysql_select_db("$DBName") or die("Unable to select database $DBName");
?>
<p> Customers who need to be added to the mailing list:
</p>
<?php
$result = @mysql_query("SELECT email FROM orders");
// This will list results
// while ( $row = mysql_fetch_array($result) ) {
// echo($row["email"] . "<br>");
// }
// but not the results I need!
// Connect to the 2nd database server
mysql_select_db($DB2Name) or die("Unable to select database $DBName");
$result2 = @mysql_query("SELECT email FROM phplist_user_user WHERE confirmed = '$1'");
/* How do I make a statement that will compare the two and loop and output until the adresses on $result that are not on $result2 are all displayed in a list?*/
?> I don't mind more trial and error but I do need some direction.
Gruntre
to echo output a list of the email adresses from the first query that do not appear on the second query
Your question is in regards to Structured Query Language (SQL) and the concept you are referring to is joining tables. To get the result you can use any join syntax you like provided you include DISTINCT in your select list. I'll show an example using a UNION JOIN, which is only available in MySQL >= 4.0
$query = "SELECT email FROM orders UNION DISTINCT SELECT addr FROM phplist_user WHERE confirmed = '$1'";
Note on MySQL DISTINCT:
The DISTINCT keyword is an optional word (introduced in MySQL 4.0.17). It does nothing, but is allowed in the syntax as required by the SQL standard.