RE: [PHP-WIN] Fields from multiple tables & fetch-array - how?
| From: | Ignatius Teo | Date: | Fri, 27 Oct 2000 00:31:44 +0000 |
| Subject: | RE: [PHP-WIN] Fields from multiple tables & fetch-array - how? | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-3545@lists.php.net to get a copy of this message | ||
I think someone has already responded to this, but I'll reiterate:
If you have multiple fields with the same name returning from a select query, the fields will be
renamed as NAME, NAME1, NAME2, NAME3....
What you might want to do is use the AS [column_name] construct:
SELECT products.name AS Product_Name, products.description, categories.name AS Category_Name,
subcategories.name AS SubCategory_Name FROM products, categories, subcategories;
Ignatius
> -----Original Message-----
> From: Giovanni Moretti [mailto:Giovanni@reflections.co.nz]
> Sent: Tuesday, 24 October 2000 06:03
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] Fields from multiple tables & fetch-array - how?
>
>
> Hi
>
> 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"]?
>
> I really DON'T want to have to list out all the fields I want
> retrieved and
> then use:
>
> $prod_name = $row[0];
> $cat_name = $row[2];
> $subcat_name = $row[3];
>
> as there are around twenty fields and I'd rather not have to
> count them all
> explicitly - too easy to miscount :-)
> Maybe I could put the three name fields first and use $row[0]
> syntax for
> these, and $row["description"] style for the rest ...
>
> Any thoughts
>
> Thanks
> Giovanni
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~~~~~
> Giovanni Moretti * FAST PIC 16F84, Atmel 2051 & AVR
> development on SimmStick
> Palmerston North * Fringe Science, Brainwave Synchronisation,
> Remote Viewing
> New Zealand *
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~ ZL2BOI ~~~~~* Visit Reflection Technology
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~~~~~
> Giovanni Moretti * FAST PIC 16F84, Atmel 2051 & AVR
> development on SimmStick
> Palmerston North * Fringe Science, Brainwave Synchronisation,
> Remote Viewing
> New Zealand *
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~ ZL2BOI ~~~~~* Visit Reflection Technology
>
>
>