PHP] Re: getting values by a joints mysql query
| From: | Michael P. Carel | Date: | Thu, 20 Jun 2002 05:01:16 +0000 |
| Subject: | PHP] Re: getting values by a joints mysql query | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-103076@lists.php.net to get a copy of this message | ||
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