You can either use the array's key value to distinguish between fields
with the same or select them using AS.
 
For the first solution, where the name fields are the 2nd 3rd and 4th
fields selected, the php code would look something like this:
 
$resultArray = mysql_query("SELECT statement");
while ($row = mysql_fetch_row($resultArray))
{
 $Section = $row[1];
 $District = $row[2];
 $Building = $row[3];
}
 
For the second, just change the select statement to something like 
"SELECT section.Name AS s_Name, district.Name AS d_Name, building.Name
AS b_name ..."
 
I liked your question - it's an excellent reminder to all of us not to
choose fieldnames that are as generic as "Name"!
 
Ellen V. Coen
Database Programmer
Brooklyn Museum
[EMAIL PROTECTED]
718.638.5000 x578

________________________________

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Wednesday, February 14, 2007 8:42 AM
To: [email protected]
Subject: [mysql] Syntax / PHP



Hi, 

Hope everyone forgives a rookie question. I am very new to PHP and are
just starting to use it in the developments of my web components. I have
been using MySQL for about two years now and love it. 

The question I had was one of syntax. I am trying to echo out a lists of
sections, districts, and buildings. All of these are in their own
tables. My problem comes up with "$Section = $row[Name];". The tables I
have are the following with the field 'Name' appearing in each table: 

`section`.`Name` 
`district`.`Name` 
`building`.`Name` 

Then I have: 

$Section = $row[Name]; 
$Building = $row[Name]; 

See my problem? "Name" is the same field name in two different tables. I
tried to do something like: 

$Section = $row[`section`.`Name`]; 

As you can imagine when I echo that out all I get is $Building. Am I
missing some basic syntax, or is there a better methodology that I
should be utilizing? 

If anyone wouldn't mind helping out a rookie I'd much appreciate it.
Thanks! 

PS: Further down my query I do have several LEFT JOIN's that link up the
tables based upon their keys (`section`.`Section_Num`, etc.) 

****************************
Sincerely,
Gary R. Ciszewski
Automation Support Librarian
WNY Regional Information Center
Erie 1 BOCES
355 Harlem Road
West Seneca, NY 14224
PH:(716) 821-7202
PH: 1-800-872-0780, x7202
FX:(716) 821-7498
[EMAIL PROTECTED]
"The world is not enough."
http://wnyslscat.wnyric.org
http://erie1sls.wnyric.org
------------------------------------------------------------------

_______________________________________________
New York PHP Community MySQL SIG
http://lists.nyphp.org/mailman/listinfo/mysql

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to