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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux