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
Php being an open source is there any support available to it?
How to read one character from a file?
What is the difference between $argv and $argc? Give example?
Will react hooks replace redux?
How to track user logged out or not? When user is idle?
What does trim () do in javascript?
How to convert numbers to strings in php?
What is php programming used for?
What is a helper function?
What does explode do in php?
Is laravel easy to learn?
How to convert one date format into another in php?
What is the main difference between asp net and php?
Which array function checks if the particular key exists in the array?
What is the mysql injection?