Re: Making a Variable from different tables with Matching Dbfields?
| From: | Shawn McKenzie | Date: | Thu, 29 Jan 2009 21:54:40 +0000 |
| Subject: | Re: Making a Variable from different tables with Matching Dbfields? | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-287377@lists.php.net to get a copy of this message | ||
Shawn McKenzie wrote:
> Terion Miller wrote:
>> Well upon looking it was number 2, I had no orders in the workorder table,
>> but here is an oddity I wonder if someone can explain if I run this simple
>> query:
>>
>> $query = "SELECT * FROM admin, workorders
>> WHERE admin.UserName = '".$_SESSION['user']."'
>> ";
>>
>> It returns adminID = 7 (my number is 20) username= tmiller (this is correct)
>>
>>
>> it's the only query I can get to return anything but it's the wrong adminID
>> can someone explain what can be making that happen
>>
>
> You cannot return related values from 2 tables without joining the
> tables in the query which we've shown is not going to work because you
> need to get AdminID from admin before you can join it to workorders.
>
> What your query says is, "give me all fields for all rows from admin,
> where UserName = the session user, and give me the same number of rows
> from workorders arbitrarily or just the first however many rows". I
> would be willing to bet that the first record in workorders has AdminID = 7.
>
> This works, obviously:
>
> $query = "SELECT * FROM admin WHERE admin.UserName =
> '".$_SESSION['user']."' ";
>
I also bet that now that you know there are no valid records for your
query in the workorders table, that the join queries that others have
provided will work great!
--
Thanks!
-Shawn
http://www.spidean.com