Re: [PHP] Query for two fields with the same name

2006-04-20 Thread admin
Maybe something like this :

$connection = SELECT t2.id AS idtwo, t1.id AS idone FROM connection AS
t1, pr AS t2 WHERE t1.area_id
= '$gateway_link' AND t1.pr_id = t2.id;

 This is probably a simple question, but I can't seem to find the
 answer online.

 I'm using this query:

 $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.

 --
 Kevin Murphy
 Webmaster: Information and Marketing Services
 Western Nevada Community College
 www.wncc.edu
 775-445-3326

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



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



Re: [PHP] Query for two fields with the same name

2006-04-20 Thread Richard Lynch
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 useas 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



[PHP] Query for two fields with the same name

2006-04-19 Thread Kevin Murphy
This is probably a simple question, but I can't seem to find the  
answer online.


I'm using this query:

$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.


--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326

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



Re: [PHP] Query for two fields with the same name

2006-04-19 Thread Jochem Maas

NOT a php question.

Kevin Murphy wrote:
This is probably a simple question, but I can't seem to find the  answer 
online.


I'm using this query:

$connection = select * from connection, pr WHERE connection.area_id  = 
'$gateway_link' and connection.pr_id = pr.id;


doing SELECT * FROM bla is not recommended, better to actually specify _just_
the fields you need.

SELECT c.id AS cid, p.id AS pid FROM connection AS c, pr AS p WHERE ... 

this stuff can be found in the mysql docs.



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.




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