homepage Welcome to WebmasterWorld Guest from 174.129.130.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
Simple script question
gruntre




msg:971052
 7:39 am on Mar 12, 2005 (gmt 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.
<?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




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved