473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

question about mysql_fetch_array ()

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
2 1632

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark | last post by:
A beginner in this area, I have been able to read a record from a MySQL database and populate an HTML form (wow!). Now, my goal is to allow the user to edit the contents of the form and then...
5
by: james | last post by:
I am new to PHP and am trying to run a simple query and display the result, with no luck. Here is the code I am using. <?php //start session session_start(); //store cmpid from querystring...
5
by: Irlan agous | last post by:
Hello all, I have a mysql select query and got it in an array $query = "select persid from reactie"; $result = mysql_query($query); $query_data = mysql_fetch_array($result);// Haal de...
15
by: Good Man | last post by:
Hey there I have a dumb question.... Let's say i have a database full of 4000 people.... I select everything from the database by: $result = mysql_query("SELECT * FROM People");
2
by: Dave Moore | last post by:
Hi All, I've got a simple query hopefully somebody can clear up for me. I need to make a query on a database to select a set of table rows, using something like: $result = mysql_query($query);...
4
by: Marcel Brekelmans | last post by:
Hello, I seem to get an extra empty field in every 'mysql_fetch_array' command I issue. For example: I have a simple table 'tblName': ID Name 1 Jane 2 Joe 2 Doe
2
by: cpptutor2000 | last post by:
Could some PHP guru please help me? I am creating a dynamic dropdown list using a code snippet(Section A) as below: Section A: $sql_query=mysql_query("SELECT DISTINCT semester, year from...
1
by: Bit Byte | last post by:
PHP noob here (background in C++/C/Java though) I want to return dummy data from a stub function, this stub function should replicate data from a database. Any idea how I can write this stub...
2
by: dylanhughes | last post by:
I'm looking for an example of a login system that has multiple fields (2 to be exact) + password. e.g username, company name and password, the user, company and password are checked against a mysql...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.