[thelist] MySQL table joins

Adrian adrian at logo-logic.com
Thu Aug 30 06:52:21 CDT 2001


Hi guys and Gals,
Now I promise that I did read the online manual but I dont think it was
written with me in mind.  There was no pictures....

Im trying to check to see if an email address is already in one of several
tables and if it isnt then add it to another table.  Pretty straight forward
stuff.
The bit of code below actually works..it checks to see if the email address
exists in tblDockets and if it doesnt then inserts it into tblEmails.
Yahoo.
<snip code>
$db->do("INSERT INTO tblEmails (emailName,Email) VALUES('".
sqlEncode($form{'toname'}) . "','". sqlEncode($form{'email'}) . "')")
unless$db->selectrow_array("SELECT Email FROM tblDockets WHERE Email='".
sqlEncode($form{'email'}) . "' OR '". sqlEncode($form{'email2'}) . "'");
</snip code>
The code doesnt work when I start trying to get it to look through a couple
of tables to see if the email address exists.  Like this
 <snip code>
$db->do("INSERT INTO tblEmails (emailName,Email) VALUES('".
sqlEncode($form{'toname'}) . "','". sqlEncode($form{'email'}) . "')")
unless$db->selectrow_array("SELECT Email FROM tblDockets, tblEmails, tblAds,
tblAdvise WHERE Email='". sqlEncode($form{'email'}) . "' OR '".
sqlEncode($form{'email2'}) . "'");
</snip code>
I have a sneaking suspicion that I cant do what I want to do.  I think I
have the right syntax for the table references before the WHERE statement
but it all turns bad after that.  Matter of fact Im sure Im not doing it
right.
The MySQL docs give this example
select * from table1,table2 where table1.id=table2.id;
which I think is totally different to what I want.
Your thoughts and comments would be appreciated (even more so if you can do
it with pictures)
Regards
Adrian Fischer
Australia





More information about the thelist mailing list