Re: Query for two fields with the same name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, April 19, 2006 5:55 pm, Kevin Murphy wrote:
> $connection = "select * from connection, pr WHERE connection.area_id
> = '$gateway_link' and connection.pr_id = pr.id";
>
> Both tables have a field called ID but they have different
> information in them. $row['id'] gets me the one from the table called
> "pr" but I need to call the ID from the table connection.

You have now stumbled into ONE of many reasons why "SELECT *" is just
Bad Code. :-)

Figure out which fields you REALLY need and specify them by name in
place of *

In addition, to actually solve your problem, you'll be able to do
something like:

SELECT pr.id as pr_id, connection.id as connection_id, area_id, ...

You can use   " as XYZ" to sort of "rename" any column you want on the
fly, and that is what it will be called.

It's also really handy when you have formulas in your select:

SELECT (x.size + y.size) as sum, x.id, y.id from x, y ...

Without the "as sum" $row['something goes here'] will have your sum
answer, but what will it be called?

I don't even know the answer to that one, cuz whatever it is, it's
just too painful compared to using 'sum'

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux