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

question about mysql_fetch_array ()

P: n/a
given the query:

SELECT * FROM customers
left join addresses
on customer.cusid=addresses.cusid

The mysql monitor returns all fields from both tables, including
repeating the field matching the on condition (cusid).

mysql_fetch_array() does not return the matching field from the joined
table.

If I use the using() conditional I get the same non repeated result, in
both mysql monitor and mysql_fetch_array().

Is it safe rely on this non repeating property of the
mysql_fetch_array() function?

I'm not sure it really makes a difference since data assignment would be
in the form of DataFromField= $row["cusid"], but I have learned from
experience that thinking something will never make any difference is risky.

Oct 1 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a

William Gill schreef:
given the query:

SELECT * FROM customers
left join addresses
on customer.cusid=addresses.cusid

The mysql monitor returns all fields from both tables, including
repeating the field matching the on condition (cusid).

mysql_fetch_array() does not return the matching field from the joined
table.

If I use the using() conditional I get the same non repeated result, in
both mysql monitor and mysql_fetch_array().

Is it safe rely on this non repeating property of the
mysql_fetch_array() function?

I'm not sure it really makes a difference since data assignment would be
in the form of DataFromField= $row["cusid"], but I have learned from
experience that thinking something will never make any difference is risky.
Stop using * and all is fine.
If you have a column that is named the same in both tables, use 'as' to
diffentiate.
Allthough I never use msql, my guess is that mysql_fetch_array() will
overwite the values of the first returned column when it parses the
second: eg:
$RS[0]["cusid"] = ...
$RS[0]["cusid"] = ...
So the first is gone.

Solution: do not use *, it is sloppy, slower, and just lazy.

Regards,
Erwin Moller

--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Oct 1 '08 #2

P: n/a

I ran into that especially if you use a lot of left joins.. what I do
now is i make sure the correct value is assigned in my query:

MySQL code includes lines like:

SELECT ...
b.fieldname AS fieldname
....
FROM....
btable AS b
....

where the are multiple instances of fieldname in various tables, but
btable has the known true value.
Oct 1 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.