RE: [PHP] PHP] Re: getting values by a joints mysql query

From: Date: Thu, 20 Jun 2002 05:11:43 +0000
Subject: RE: [PHP] PHP] Re: getting values by a joints mysql query
Groups: php.general 
Request: Send a blank email to php-general+get-103077@lists.php.net to get a copy of this message
use mysql_error() or whatever it's called to see if there's some problem executing the query -----Original Message----- From: Michael P. Carel [mailto:mikecarel@teamglac.com] Sent: Thursday, June 20, 2002 3:01 PM To: php Subject: [PHP] PHP] Re: getting values by a joints mysql query 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!

« previous php.general (#103077) next »