Thank you everyone for your replies. When I read them I suddenly realized it was so obvious. I adjusted my query and everything worked out fine. Until I reach my next mental block. Thanks again!
**************************** 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 ------------------------------------------------------------------ [EMAIL PROTECTED] Sent by: [EMAIL PROTECTED] 02/14/2007 09:29 AM Please respond to [email protected] To [email protected] cc Subject mysql Digest, Vol 4, Issue 1 Send mysql mailing list submissions to [email protected] To subscribe or unsubscribe via the World Wide Web, visit http://lists.nyphp.org/mailman/listinfo/mysql or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than "Re: Contents of mysql digest..." Today's Topics: 1. Syntax / PHP ([EMAIL PROTECTED]) 2. RE: Syntax / PHP (Peter Sawczynec) 3. RE: Syntax / PHP (Peter Sawczynec) 4. Re: Syntax / PHP (Rob Marscher) 5. RE: Syntax / PHP (Ellen Coen) ---------------------------------------------------------------------- Message: 1 Date: Wed, 14 Feb 2007 08:42:09 -0500 From: [EMAIL PROTECTED] Subject: [mysql] Syntax / PHP To: [email protected] Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="us-ascii" 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 ------------------------------------------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.nyphp.org/pipermail/mysql/attachments/20070214/fe865e56/attachment-0001.htm ------------------------------ Message: 2 Date: Wed, 14 Feb 2007 09:16:26 -0500 From: "Peter Sawczynec" <[EMAIL PROTECTED]> Subject: RE: [mysql] Syntax / PHP To: "'MySQL SIG'" <[email protected]> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="us-ascii" SELECT t1.name, t2.name FROM table1 AS t1, table2 AS t2 WHERE t1.id = t2.id Are you looking for that form? Warmest regards, Peter Sawczynec Technology Dir. Sun-code.com Web related services 646.316.3678 [EMAIL PROTECTED] -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, February 14, 2007 8:42 AM To: [email protected] Subject: [Norton AntiSpam] [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 ------------------------------------------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.nyphp.org/pipermail/mysql/attachments/20070214/3f813858/attachment-0001.htm ------------------------------ Message: 3 Date: Wed, 14 Feb 2007 09:19:07 -0500 From: "Peter Sawczynec" <[EMAIL PROTECTED]> Subject: RE: [mysql] Syntax / PHP To: "'MySQL SIG'" <[email protected]> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="us-ascii" Sorry, but further you are probably looking for this complete set of aliasing in your query: SELECT t1.name AS SectionName, t2.name AS DistrictName FROM table1 AS t1, table2 AS t2 WHERE t1.id = t2.id This above query will return fields with the distinct alias names you gave them. I believe that should do it. Warmest regards, Peter Sawczynec Technology Dir. Sun-code.com Web related services 646.316.3678 [EMAIL PROTECTED] -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Wednesday, February 14, 2007 8:42 AM To: [email protected] Subject: [Norton AntiSpam] [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 ------------------------------------------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.nyphp.org/pipermail/mysql/attachments/20070214/7fc85dac/attachment-0001.htm ------------------------------ Message: 4 Date: Wed, 14 Feb 2007 09:20:28 -0500 From: Rob Marscher <[EMAIL PROTECTED]> Subject: Re: [mysql] Syntax / PHP To: MySQL SIG <[email protected]> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed [EMAIL PROTECTED] wrote: > 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: You need to give an alias for each of those name columns in order to access it that way: Select section.Name as section_name, district.Name as district_name, etc... Then you can do: $Section = $row['section_name']; Alternatively, you can access them by the numerical index in $row, but that's not very reliable because if your query changes at all, you'll have to update your variable assignments. This is what I'm talking about: Select section.Name, district.Name, etc... $Section = $row[0]; $District = $row[1]; I'd recommend the first way. -Rob ------------------------------ Message: 5 Date: Wed, 14 Feb 2007 09:28:51 -0500 From: "Ellen Coen" <[EMAIL PROTECTED]> Subject: RE: [mysql] Syntax / PHP To: "MySQL SIG" <[email protected]> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="us-ascii" 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 ------------------------------------------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.nyphp.org/pipermail/mysql/attachments/20070214/aa78096f/attachment.htm ------------------------------ _______________________________________________ mysql mailing list [email protected] http://lists.nyphp.org/mailman/listinfo/mysql End of mysql Digest, Vol 4, Issue 1 *********************************** -- BEGIN-ANTISPAM-VOTING-LINKS ------------------------------------------------------ Teach CanIt if this mail (ID 64519774) is spam: Spam: http://milton1.wnyric.org/canit/b.php?c=s&i=64519774&m=efd5c8bf1eb2 Not spam: http://milton1.wnyric.org/canit/b.php?c=n&i=64519774&m=efd5c8bf1eb2 Forget vote: http://milton1.wnyric.org/canit/b.php?c=f&i=64519774&m=efd5c8bf1eb2 ------------------------------------------------------ END-ANTISPAM-VOTING-LINKS
_______________________________________________ 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
