Welcome to WebmasterWorld Guest from 54.167.82.170

Forum Moderators: brotherhood of lan & mack

Message Too Old, No Replies

Simple script question

     

gruntre

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

10+ Year Member



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.
<?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

coopster

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

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



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

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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month