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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of inner join in mysql?

524


What's the difference between accessing a class method via -> and via ::?

516


How to get length of an array in PHP?

559


How many escape sequences are recognized in double-quoted strings in php?

526


Why shouldn't I use mysql_* functions in php?

574






Is age interval or ordinal?

514


Does https prevent csrf?

504


How arrays are used in php?

540


Explain me what are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?

479


What is difference between explode() or split() in PHP?

486


What is a helper function?

531


What does isset() function?

533


What are sql functions?

526


How to increase the maximum execution time of a script in php?

519


What are the advantages of indexes in php?

552