Re: Array Question
| From: | tg-php at gryffyndevelopment dot com | Date: | Fri, 17 Aug 2007 17:06:15 +0000 |
| Subject: | Re: Array Question | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-28378@lists.php.net to get a copy of this message | ||
I assume you're getting fields with the same name from pulling data from two or more tables.
Something like "SELECT * FROM TABLE1, TABLE2 WHERE TABLE1.id = TABLE2.id" or something
like that.
At any rate, if you can.. it's always good to name the fields you want to pull instead of using
"SELECT *". I know it's a pain sometimes, but in this case it may be somewhat
necessary.
What you can do is use an alias for the duplicate field name. Something like this:
"SELECT TABLE1.id as id1, TABLE2.id as id2 FROM...."
Then in your array, it'll be $mydata['id1'] and $mydata['id2']
Works the same with a single table pull and I usually alias the table names too:
SELECT t1.id id1, t2.id id2 FROM TABLE1 t1, TABLE2 t2 WHERE t1.id = t2.id
(can't remember if you can use the alias in the WHERE to make it "id1 = id2" or not)
The "as" is usually optional, but sometimes nice to keep things clear. In some flavors of
SQL it's required.
-TG
= = = Original message = = =
I have pull a bunch of data from an SQL database through a query. The problem I am running into is
I pull two fields with the exact same name. How do I grab the right info? I have been using mydata
~ the array name. mydata['contactID'] Should I instead use the array value so mydata[8]?
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.