Re: Fields from multiple tables & fetch-array - how?

From: Date: Wed, 25 Oct 2000 18:47:03 +0000
Subject: Re: Fields from multiple tables & fetch-array - how?
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-3471@lists.php.net to get a copy of this message
Giovanni Moretti wrote: > I'm wanting to retrieve data from multiple tables that each have a field > called NAME. Is this possible using the MYSQL_FETCH_ARRAY function ? > > eg: > > $query = "SELECT products.name, products.description, categories.name, > subcategories.name " . > "FROM products, categories, subcategories" ; > $results = SQL_Update($query); // run the query > > while ( $row = mysql_fetch_array($results)): > $name = $row["name"]; <-------- WHICH NAME will be returned? > $description = $row["description"]; > endwhile; > > Is it possible to use this syntax, possibly using something like $prod_name = > $row["products.name"]? You'd want to use the syntax "SELECT <fieldname> AS <alternatename> ..." Something like this... <?php $query = "SELECT products.name AS prodname, products.description, categories.name AS catname, subcategories.name AS subcatname FROM products, categories, subcategories"; $results = SQL_Update($query); // run the query while ( $row = mysql_fetch_array($results)) { $prodname = $row["prodname"]; $description = $row["description"]; $catname = $row["catname"]; $subcatname = $row["subcatname"]; } ?> Make sense? -- Andy Hoffman Web Developer Bristol-Myers Squibb office: LVL G1.2607 email: andy.hoffman@bms.com phone: 609-252-5788

« previous php.windows (#3471) next »