Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


what is the difference between mysql_fetch_array() and
mysql_fetch_row()?

Answers were Sorted based on User's Feedback



what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / vijay kumar singhal

wrong, instead both returns all the rows from table. The
difference between them is fetch_array return result in
assoc array as well as numeric array and you can also
specify which specific type of array you want by providing
second paramter to the function while fetch_row return
result in numeric array only.

fetch_row : Array( [0]=>vijay)
fetch_array : Array([0]=>vijay [name]=>vijay)

Is This Answer Correct ?    131 Yes 13 No

what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / srinivas1982

sorry for my mistake. here is the answer
the functions mysql_fetch_row(), mysql_fetch_array() and
mysql_fetch_object() return one row from the result, and
then move the pointer on. If there are no more rows to
fetch, it returns false. This means you can you use a very
simple while loop:

$result=mysql_query("SELECT * FROM sometable");
while($row=mysql_fetch_row($result)){
do_something_with_row();
}

This will automatically terminate when the last row has been
processed.

the difference between mysql_fetch_row() and
mysql_fetch_array() is that the first returns the results in
a numeric array ($row[0], $row[1] etc), while the latter
returns a the results an array containing both numeric and
associative keys ($row["name"], $row["email"] etc).
mysql_fetch_object() returns an object ($row->name,
$row->email etc).

Is This Answer Correct ?    60 Yes 12 No

what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / tarun singhal

mysql_fetch_array: returned a row from recordset as a
numeric and/or associative array.

mysql_fetch_row: returned a row from recordset as numeric array.

example:
$con=mysql_connect("localhost","root","root");
$sql = "select * from member where id=1";
$result=mysql_query($sql,$con);
print_r(mysql_fetch_array($result));
print_r(mysql_fetch_row($result));

Is This Answer Correct ?    38 Yes 9 No

what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / piyush patel

mysql_fetch_array:

This function return row as an associative array, a numeric
array, or both. you can refer to outputs as databases
fieldname rather then number.
example :
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
print "$row['name']";
print "$row['mobile']";
}

mysql_fetch_row :

This function return row as an enumrated array and each row
contain a unique ID.
example:
$result=mysql_query($query);
while($row=mysql_fetch_row($result))
{
print "$row[0]";
print "$row[1]";
print "$row[2]";
}

Is This Answer Correct ?    30 Yes 12 No

what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / sowmya mn

mysql_fetch_assoc — Fetch a result row as an associative array
mysql_fetch_array — Fetch a result row as an associative
array, a numeric array, or both
mysql_fetch_row — Get a result row as an enumerated array

Is This Answer Correct ?    17 Yes 7 No

what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / amit

mysql_fetch_array() will return result row as associative or
nueric array or both.While mysql_fetch_row() will return
result row as array & return only single row.

Is This Answer Correct ?    11 Yes 5 No

what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / 585858

mysql_fetch_array()works as an associative array i.e. just
use the field name specified in your database to access the
values while mysql_fetch_row() returns the value of a
single field in a particular row if you r going to specify
the array's index which starts from '0'.

Is This Answer Correct ?    3 Yes 1 No

what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / sekhar

mysql_fetch_array($resultset, [return type]);
return a row from the result set as an array
return type values:
MYSQL_NUM If return type is mysql_num, we have to use the
column position in the result set.
MYSQL_ASSOC: if return type is mysql_assoc, we have to fetch
the data by using column names in result set.
MYSQL_BOTH: if return type is mysql_both, we have to fetch
the data by using column index or column names in the result
set.

mysql_fetch_rows($resultset);
retrives the row from the result set and move the pointer to
the next record.
we have to retrive the data from the row by using the filed
position in the result set.

mysql_fetch_assoc($resultset);
retrives a row from the resultset as an associative array.
we have to retrive the data by using the columns name in the
result set.

mysql_fetch_object($resultset);
return the row as an object. we have to fetch the data in
the row fetch the column names in the result set as $row->
column name in the result set.

Is This Answer Correct ?    11 Yes 10 No

what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / deepaa

There is not so much difference between the
mysql_fetch_array and mysql_fetch_assoc in the sense that
both can fullfill your requirements but it depends on your
need and ease of use. I prefer mysql_fetch_array because
with it i can use both indexed value and associative value.

I will explain this difference with short example:
$sql = mysql_fetch_array(‘select name, address from
tbl_customer’);
It means that you are getting answer directly into an array
, and you dont need to know the field value of the elements
to be outputed.
Just print the output as:

foreach($sql as $ans){
echo $ans[0].' lives in '.$ans[1];
}
or
foreach($sql as $ans){
echo $ans['name'].' lives in '.$ans['address'];

}

mysql_fetch_assoc, you can output the result as $ans['name']
but not $ans[0] . What i want say is you need to know about
the field name of the table. Ok here is the sample code:

foreach($sql as $ans){
echo $ans['name'].' lives in '.$ans['address'];
}
But not
foreach($sql as $ans){
echo $ans[0].' lives in '.$ans[1];

}

Is This Answer Correct ?    2 Yes 2 No

what is the difference between mysql_fetch_array() and mysql_fetch_row()?..

Answer / prabhu

how to fetch the particular row in multiple rows in phpmysql?

Is This Answer Correct ?    3 Yes 3 No

Post New Answer



More PHP Interview Questions

what is CURL?

0 Answers  


Single choice objective PHP question...

1 Answers  


Why super () is used in java?

0 Answers  


Is php the same as html?

0 Answers  


Tell us how to create an array of a group of items inside an html form?

0 Answers  






Tell me how do you define a constant?

0 Answers  


Can we set session value in javascript?

0 Answers  


Explain the installation of PHP on UNIX systems?

0 Answers  


What is the role of php?

0 Answers  


What are major variables in research?

0 Answers  


Explain me what is the meaning of a persistent cookie?

0 Answers  


Tell me is it possible to protect special characters in a query string?

0 Answers  






Categories