Welcome to WebmasterWorld Guest from

Forum Moderators: keyplyr & mack

Message Too Old, No Replies

Simple script question

7:39 am on Mar 12, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 21, 2003
votes: 0

I'm not sure if this is the right place for this but I don't want to annoy the guys at the PHP forum with my real beginers attempts at PHP/MYSQL.
My question is can anyone help me with the right peice of code to get the following script to echo output a list of the email adresses from the first query that do not appear on the second query. I'm sure this is a simple thing but my hours of trial and error have only led to failure and frustration.
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:
$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.


11:41 am on Mar 12, 2005 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 2

Don't worry, gruntre, we don't get annoyed very easily ;)
Everyone is welcome here and we all understand that we each began somewhere.

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'";

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.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members