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

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

 



I'm not sure what you mean by trim the posts, please explain so I can spare
folks from redundant text.

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']."' ";

    $result = mysql_query ($query);
    $row = mysql_fetch_assoc ($result);

    echo $row['AdminID'];

thanks again!!
terion


On Wed, Jan 28, 2009 at 4:28 PM, Chris <dmagick@xxxxxxxxx> wrote:

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

[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