473,801 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about mysql_fetch_arr ay ()

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_arr ay() 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_arr ay().

Is it safe rely on this non repeating property of the
mysql_fetch_arr ay() 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 1655

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_arr ay() 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_arr ay().

Is it safe rely on this non repeating property of the
mysql_fetch_arr ay() 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_arr ay() 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
10554
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 update the record in MySQL. The problem is, as soon as the "Update" button (type="submit") is pressed, all of the data disappear from the form. How can that be prevented? Here is my code:
5
2029
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 $_SESSION = $_GET;
5
1715
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 gegevens uit de tabel
15
2689
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
6107
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); I can then use mysql_fetch_array in a while loop to access each row in the result. This all works fine.
4
2967
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
1628
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 schoolproject_pics ORDER BY year DESC"); echo "<select name=\"semester\" onchange=\"GoTo()\">"; echo "<option value=\"$semester\">-Semester Year-</option>"; while($data = mysql_fetch_array($sql_query)){ if($data==@$semester && $data==@$year){
1
2199
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 function? i.e. something like this: function foo (){
2
1934
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 database. I have it working with just the username field but I'm confused on how to go about adding another field. I'm pretty new to PHP so don't beat me up too much for this example code, I borrowed and hacked it together in a very short period...
0
10515
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10291
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10260
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10049
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9100
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7589
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6827
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.