Dear all,
I want to know the difference between mysql_fetch_arr ay() and
mysql_fetch_row ().
I know that mysql_fetch_row () return data in numeric array while
mysql_fetch_arr ay() return data in numeric as well as in associative
array.
But my question is, why it returns in both format. Is it wastage of
memory ?
Why this wastage is necesarry ?
Thanks in advance.
BYe. 4 1770
pradeep wrote:
Dear all,
I want to know the difference between mysql_fetch_arr ay() and
mysql_fetch_row ().
I know that mysql_fetch_row () return data in numeric array while
mysql_fetch_arr ay() return data in numeric as well as in associative
array.
But my question is, why it returns in both format. Is it wastage of
memory ?
Why this wastage is necesarry ?
Hi,
The answer is simple, if you want an assoc array, you can use
mysql_fetch_arr ay().
I always prefer constructs like this in my code:
echo $row["firstname"];
above
echo $row[3];
Since the former leaves you without doubt which column you are using.
And also: If you expand your query to get more columns, an index of an
array might easily get you confused.
But if you like the array-indexes more, just use them.
I expect there must be less overhead involved when no assoc arrays are
created and returned.
So as far as I can tell: it is not a waste of memory, but it offers you
the choice what you want:
1) faster code/less IO (use only indexes)
2) better readable/more robust code. (use assoc arrays)
just my 2 cent.
Regards,
Erwin Moller
>
Thanks in advance.
BYe.
On 26 Nov, 09:29, pradeep <pwprad...@gmai l.comwrote:
Dear all,
I want to know the difference between mysql_fetch_arr ay() and
mysql_fetch_row ().
I know that mysql_fetch_row () return data in numeric array while
mysql_fetch_arr ay() return data in numeric as well as in associative
array.
So you know the difference then
>
But my question is, why it returns in both format. Is it wastage of
memory ?
It returns in both formats because that is what it was built to do.
>Is it wastage of memory ?
It is only a waste if you don't need both array types. If you only
want numeric use mysql_fetch_row (), or you can use msql_fetch_arra y()
with the MSQL_NUM constant. If you only want associative then use
MSQL_ASSOC.
Why this wastage is necesarry ?
Thanks in advance.
BYe.
Erwin Moller wrote:
pradeep wrote:
>Dear all,
I want to know the difference between mysql_fetch_arr ay() and mysql_fetch_ro w().
I know that mysql_fetch_row () return data in numeric array while mysql_fetch_ar ray() return data in numeric as well as in associative array.
But my question is, why it returns in both format. Is it wastage of memory ? Why this wastage is necesarry ?
Hi,
The answer is simple, if you want an assoc array, you can use
mysql_fetch_arr ay().
I always prefer constructs like this in my code:
echo $row["firstname"];
above
echo $row[3];
Since the former leaves you without doubt which column you are using.
And also: If you expand your query to get more columns, an index of an
array might easily get you confused.
But if you like the array-indexes more, just use them.
I expect there must be less overhead involved when no assoc arrays are
created and returned.
So as far as I can tell: it is not a waste of memory, but it offers you
the choice what you want:
1) faster code/less IO (use only indexes)
2) better readable/more robust code. (use assoc arrays)
just my 2 cent.
Regards,
Erwin Moller
>> Thanks in advance.
BYe.
Erwin,
The overhead in creating an associative array is negligible.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
Jerry Stuckle wrote:
Erwin Moller wrote:
>pradeep wrote:
>>Dear all,
I want to know the difference between mysql_fetch_arr ay() and mysql_fetch_r ow().
I know that mysql_fetch_row () return data in numeric array while mysql_fetch_a rray() return data in numeric as well as in associative array.
But my question is, why it returns in both format. Is it wastage of memory ? Why this wastage is necesarry ?
Hi,
The answer is simple, if you want an assoc array, you can use mysql_fetch_ar ray().
I always prefer constructs like this in my code: echo $row["firstname"];
above
echo $row[3];
Since the former leaves you without doubt which column you are using. And also: If you expand your query to get more columns, an index of an array might easily get you confused.
But if you like the array-indexes more, just use them. I expect there must be less overhead involved when no assoc arrays are created and returned.
So as far as I can tell: it is not a waste of memory, but it offers you the choice what you want: 1) faster code/less IO (use only indexes) 2) better readable/more robust code. (use assoc arrays)
just my 2 cent.
Regards, Erwin Moller
>>> Thanks in advance.
BYe.
Erwin,
The overhead in creating an associative array is negligible.
Hi Jerry,
I expected so much, but never actually measured it, since I always use
assoc retrieval of columns for clearity of code.
A task must be very daunting to optimize in this kind of way.
But thanks for the info. Now I know I'll never use indexed row
retrieval. ;-)
Regards,
Erwin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
|
by: Theo |
last post by:
hi all
this is probably another simple one, but the web doesnt seem to have an
answer that I can find.
Veeeery simple code. each row has 10 columns.
require('db.php');
$query = "SELECT * FROM mytable";
|
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");
|
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.
|
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
| |
by: Petr Vileta |
last post by:
Hi, I'm new here and excuse me if this question was be here earlier.
I have a simple code
<html><body>
<?php
<?php
$link = mysql_connect("localhost", "user", "password")
or die("Grr: " . mysql_error());
mysql_select_db("my_dbf") or die("Grr");
|
by: monomaniac21 |
last post by:
hi all
im querying a db for two rows which are always returned. how can i
reference each row and output its contents without using a while loop.
ive tried:
$row = mysql_fetch_array($result);
extract $row;
echo $var1; //var 1 of row 0
echo $var1; //var 1 of row 1
|
by: Karl Groves |
last post by:
I'm trying to run mysql_fetch_array with a variable in place of the
optional result type constant, like so
mysql_fetch_array($result, $rtype) where, obviously, $rtype is one of the
three valid values for the result type. This throws an error:
"mysql_fetch_array() : The result type should
be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH."
I'm not quite sure what the issue here is, other than that I'm replacing a
constant with a...
|
by: William Gill |
last post by:
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
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |