Re: PHP] Re: getting values by a joints mysql query
| From: | Samantha Savvakis | Date: | Thu, 20 Jun 2002 06:31:23 +0000 |
| Subject: | Re: PHP] Re: getting values by a joints mysql query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-103084@lists.php.net to get a copy of this message | ||
Sounds like an issue with your SQL
Perhaps you want something like:
select U.Name, U.Title, G.GID
from Users as U, Groups as G
where U.ID = G.<ID column that matches the Users table>
and U.Id= '$Id'
"Michael P. Carel" <mikecarel@teamglac.com> wrote in message
news:018b01c21817$823dd540$4301a8c0@teamglac.com...
> I'm querying two tables which has the same Id number that's why im using
a
> joint query or referencing it as "User as U, Groups as G".
> But i cannot get the selected query "U.Name , U.Title , G.GID".
> Any idea why or how? thanks in advance.
>
> >Hi,
>
> >There is no need to reference the item as U.Name or Groups.GID
> >Simply do something like this:
>
> >$result = mysql_query($query);
> >if ($result)
> >{
> > if (mysql_num_rows($result) > 0)
> > {
> > while ($data = mysql_fetch_array($result))
> > {
> > $Name = $data["Name"];
> > $Title = $data["Title"];
> > $GID = $data["GID"];
>
> > print $Name;
> > print $Title;
> > print $GID;
> > }
> > }
> > else
> > {
> > printf("ERROR: No rows found<BR>");
> > }
> >}
> >else
> >{
> > $error = mysql_error();
> > printf("ERROR: %s<BR>", $error);
> >}
>
> >Hope this helps.
>
> "Michael P. Carel" <mikecarel@teamglac.com> wrote in message
> news:014f01c2180d$a9fd81c0$4301a8c0@teamglac.com...
> > Hi to all,
> >
> > Im having problem in getting the the result values in my cross joint
> query.
> > Here's my query:
> >
> > $query=("Select U.Name, U.Title, G.Groups from Users as U, Groups as G
> where
> > U.Id='$Id' ");
> > $result=mysql_query($query);
> > $data=mysql_fetch_array($result);
> > $Name= $data[U.Name];
> > $Title = $data[Title];
> > $GID = $data[Groups.GID];
> >
> > print $Name;
> > print $Title;
> > print $GID;
> >
> > I dont have any printed results here. But if i query the two table one
by
> > one i can have the printed result.
> > Please help!
> >
> >
> >
> > Regards,
> > Mike
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
>
>
>
>
>
> Regards,
>
> Michael P. Carel
> Systems Administrator
>
> TEAM Pacific Corporation
> Electronics Ave. FTI Complex
> Taguig, Metro Manila. 1604
> Tel no. : 63-2-8388438 Direct Line
> 63-2-8385005 local 363
>