PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 28th, 2002, 08:42 AM
MuuTuwon MuuTuwon is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bloomington, IN, USA
Posts: 25 MuuTuwon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MuuTuwon Send a message via AIM to MuuTuwon
Queston regarding printing back the results of an SQL query


I have kind of a simple queston. If you have an SQL query that looks at multiple tables, then you put the results of that query in an array, what are the names in the array?

I'm bad at explaining things, so basicly I have this..

php Code:
Original - php Code
  1.  
  2. $result = mysql_query("SELECT * FROM table1, table");
  3. $row = mysql_fetch_array($result);
  4.  
  5. ECHO "$row[what goes here?]"


Basicly I'm wondering because like, since in SQL you can reference with table_name.field_name.. then what happens if you have a field called ID in both tables? $row[ID] can't be both of them can it?

Basicly that's my queston, sorry if its wordy for being so simple.

Reply With Quote
  #2  
Old August 28th, 2002, 08:57 AM
D1NGO D1NGO is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Perth, Australia
Posts: 221 D1NGO User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Queston regarding printing back the results of an SQL query

well i spose to avoid this you could change your SQL statement:
php Code:
Original - php Code
  1.  
  2. $result = mysql_query("SELECT table.ID AS ID1, table1.ID AS ID2 FROM table1, table");


that would get around the problem i think

Reply With Quote
  #3  
Old August 28th, 2002, 01:21 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: Queston regarding printing back the results of an SQL query

what happens (i think) is that clashing names will wind up being "table1.field" and "table2.field" instead of just "field"

try going print_r($row); to make certain..

Reply With Quote
  #4  
Old August 28th, 2002, 10:43 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Queston regarding printing back the results of an SQL query

no, that is not what happens. associative arrays returned from mysql_fetch_* function always use only column name for array key.

when u use mysql_fetch_rows(), every column from first table is returned as an offset in array (ie 0..3) and every column from second table is returned also as offset, but starting where first ended (ie 4..9).

when u use mysql_fetch_assoc() table columns are returned as column_name=>column_value pairs, and since php allows only one value per one key in array, later columns with same name (ie table2.id, going as "id")will override first ones (ie table2.id going also as "id").

but when u use mysql_fetch_array() result is mix from previous two, so there are all columns with offsets (0..3 and 4..9), but only one instance of doubled coulumns (ie "id)...

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Queston regarding printing back the results of an SQL query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway