Dear all,
I want to know the difference between mysql_fetch_array() and
mysql_fetch_row().
I know that mysql_fetch_row() return data in numeric array while
mysql_fetch_array() 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 1757
pradeep wrote:
Dear all,
I want to know the difference between mysql_fetch_array() and
mysql_fetch_row().
I know that mysql_fetch_row() return data in numeric array while
mysql_fetch_array() 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_array().
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...@gmail.comwrote:
Dear all,
I want to know the difference between mysql_fetch_array() and
mysql_fetch_row().
I know that mysql_fetch_row() return data in numeric array while
mysql_fetch_array() 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_array()
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_array() and mysql_fetch_row().
I know that mysql_fetch_row() return data in numeric array while mysql_fetch_array() 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_array().
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*******@attglobal.net
==================
Jerry Stuckle wrote:
Erwin Moller wrote:
>pradeep wrote:
>>Dear all,
I want to know the difference between mysql_fetch_array() and mysql_fetch_row().
I know that mysql_fetch_row() return data in numeric array while mysql_fetch_array() 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_array().
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...
|
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 *...
|
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);...
|
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: " ....
|
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);...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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: 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,...
|
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...
| |