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

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

 




Terion Miller wrote:
>
>
>
>         Your  post made perfect sense to me about the INNER JOIN , I
>         looked it up but it is not returning the AdminID, maybe my
>         syntax is wrong?
>
>         $query =  "SELECT admin.AdminID , workorders.AdminID
>                 FROM admin
>                     INNER JOIN
>                 workorders
>                     ON  AdminID(admin, workorders)
>                 WHERE admin.UserName =   '".$_SESSION['user']."' ";
>
>
>     The syntax is wrong.
>
>     inner join workorders using (adminid)
>     ^^
>     only works if both tables are using the same field name, the db
>     will expand it into the syntax below. Here you just need to
>     specify the fieldname to join on (ie the common one).
>
>     or
>
>     inner join workorders on (admin.adminID=workorders.adminID)
>     ^^
>     if the field names are not named the same, eg:
>
>     select * from
>     comments
>     inner join users on (comments.user_id=users.id <http://users.id>)
>
> Well I tried both ways and still cannot get it to pick up the AdminID,
>
The main problem is that you've never explained what you want to get
from the query.  The replies have used your code as an example and I'm
pretty sure that's not what you want.  Unless I totally mis-understand
what you want, you have 2 options:

1. Use the 2 queries that I gave you in a previous post.
2. Use a subquery:

$sql = "SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = '" 
. mysql_real_escape_string($_SESSION['user']) . "')";

-Shawn





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