By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 1,904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

results of same field names but different tables in mySQL query.

P: n/a
LRW
I have a SQL string with a couple of JOINs that works perfectly in
command prompt. I get results for all the fields selected just fine.
But when I put it into a PHP page, I can't make variables(?) out of
fields that have the same field name from different tables.
Here's the SQL statement:

$sql = "SELECT orders.companyid,orders.ordernum,orders.address,tb l_ih_accounts.company,tbl_ih_accounts.address
FROM orderstatus ".
"LEFT JOIN orders ON (orderstatus.ordernum = orders.ordernum) ".
"LEFT JOIN tbl_ih_accounts ON (tbl_ih_accounts.id = ihid) ".
"WHERE submitted <> 'yes' ORDER BY orders.ordernum ASC";

Then in the "WHILE" clause after the database is queried:
$o_address = $row[orders.address];
$ih_address = $row[tbl_ih_accounts.address];

I've tried it without the table names in the $row statements, but then
I'll just get the results for tbl_ih_accounts.address.
I'm thinking there must be some way to uniquely "name" the results of
a particular field up in the SQL statement, and then just use that
unique name in the WHILE. But I have no clue, and can't find anything
about anything like that.

If someone can just point me to a site, or just give me the name of
the concept I can then search mysql.org or wherever and learn about
it.
Thanks!
Liam
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <3a**************************@posting.google.com >,
de**@celticbear.com (LRW) wrote:
I'm thinking there must be some way to uniquely "name" the results of
a particular field up in the SQL statement, and then just use that
unique name in the WHILE. But I have no clue, and can't find anything
about anything like that.


SELECT table1.field AS uniquename1, table2.field AS uniquename2 ...

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.