Re: Making a Variable from different tables with Matching Dbfields?

From: Date: Wed, 28 Jan 2009 22:28:10 +0000
Subject: Re: Making a Variable from different tables with Matching Dbfields?
References: 1 2 3 4 5 6 7 8 9  Groups: php.general 
Request: Send a blank email to php-general+get-287330@lists.php.net to get a copy of this message
Here are my variables when I reveal them, I am picking up the right adminID I can't figure out why it's returning random orders though: $query"SELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = 'tmiller' "
Please please please trim your posts to relevant stuff. I had to go through 4 pages of previous attempts to try and find what you posted. Trim it down to what you need to post. It's picking "random" stuff because you're not joining the tables properly. You have: select admin.AdminID, workorers.AdminID from admin, workorders WHERE admin.userName='tmiller'; You haven't told the db how to join the two tables together, so it's doing a cross or cartesian join (useful in some cases, but not here). What that means is for each row in 'admin', it will show every row in 'workorders' and vice versa. What you want is to only show rows that match up: select admin.AdminID, workorers.AdminID from admin inner join workorders using (AdminID) WHERE admin.userName='tmiller'; which means for every row in admin, make sure there is a matching row (based on the adminid) in workorders. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#287330) next »