Re: Making a Variable from different tables with Matching Dbfields?
| From: | Terion Miller | Date: | Thu, 29 Jan 2009 21:36:37 +0000 |
| Subject: | Re: Making a Variable from different tables with Matching Dbfields? | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-287374@lists.php.net to get a copy of this message | ||
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
On Thu, Jan 29, 2009 at 2:48 PM, Shawn McKenzie <nospam@mckenzies.net>wrote:
> Terion Miller wrote:
> > Hi Again
> >
> > Here is the query and code I tried:
> > $sql = "SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM
> > admin WHERE UserName = '"
> > . mysql_real_escape_string($_SESSION['user']) . "')";
> >
> >
> > $result2 = mysql_query ($sql);
> > $row2 = mysql_fetch_assoc ($result2);
> > $printrow = print_r($row2);
> >
> >
> >
> > Here is my print variables--- Nothing printed with the print_r:
> >
> > $sql "SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM
> > admin WHERE UserName = 'tmiller')"
> > $result2 "Resource id #6"
> > $row2 ""
> > $printrow "1"
> >
> O.K., easy:
>
> 1. There is no UserName in admin that = $_SESSION['user']
> 2. Or, the AdminID that is returned for $_SESSION['user'] is not present
> in workorders
>
> That's why I suggested the 2 query approach the first time so that you
> could echo out the AdminID after the first query and then go into the db
> and make sure it exists in workorders. Or, if none were returned, then
> echo out $_SESSION['user'] and make sure it exists in admin.
>
> -Shawn
>