Resolved Question
what is difference between mysql_fetch_array(),mysql_fetch_row() and mysql_fetch_object()please insert with example
 
Details:
  asked by: popular123  on: Mar 22, 2009  
 Best Answer ! ! !
sujusg 's Answer  ( this answer is maked as best answer of this question at: Mar 31, 2009 )


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

mysql_fetch_array ::Return row as anassociative or an enumrated array or both which is default .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['address']";
print "$row['city']";
}

mysql_fetch_object  :: it return as an object on the place of array.

$result=mysql_query($query);
while($row=mysql_fetch_object($result))
{
print "$row->name";
print "$row->address";
print "$row->city";
}
1 comments  answered on: Mar 24, 2009 
Other Answer (6)

what is difference between mysql_fetch_array() mys...

mysql_fetch_array():: fetches a result row as a associated array numeric array

mysql_fetch_object: Fetaches a result row as object.

mysql_fetch_row::fetches a result row as array

  introvert_guy   answered on£ºMar 24, 2009  0 comments

mysql_fetch_object -> Fetch the first single matching record of results.

mysql_fetch_array -> Fetch the all matching records of results.

  dslitemylove   answered on£ºMar 25, 2009  0 comments

mysql_fetch_row Get a result row as an enumerated arrayEach column has to be accessed as $row[0] $row[1] etcmysql_fetch_array Fetch a result row as an associative array a numeric array or both$row[0] or $row['user_id']both field name or enumerated array value can be usedmysql_fetch_object Fetch a result row as an object$row->user_id $row->pass etc
  fzz_91   answered on£ºMar 26, 2009  0 comments


Let's take one example :
one table says
create table student
(id int(5)
name varchar(50));

mysql_fetch_array:

--> it returns array as index as table field name as well as it's index number
from table student you fetch record like this:
while($res mysql_fetch_array($rs)){

echo $res['id'] ;// print id value
or
echo $res[0];// same as above statement



}

mysql_fetch_row:
--> it returns array as it's index number
from table student you fetch record like this:
while($res mysql_fetch_array($rs)){


echo $res[0];// it can fetch value by index value not table field name



}



mysql_fetch_object
--> it returns array as it's as object as table field name
from table student you fetch record like this:
while($res mysql_fetch_array($rs)){


echo $res->id;// it can fetch value by object value not table field name or it's //index



}

  namie   answered on£ºMar 27, 2009  0 comments

I will try to make you understand following points.
mysql_fetch_row: Returns row as an enumerated array mysql_fetch_object: Returns row as an object mysql_fetch_array: Returns row as an associative array
This is the table details ------------------------------------------------------ ID Name City --------------------------------------------- 1 belal Chatar 2 Sharma Ranchi 3 chand Bachra ------------------------------------------------------ $res select * from details ; $row mysql_fetch_row($res) // this return enumerated array having value
row{ 1
belal
chatra
}
so we can print $row[0] $row[1] $row[2];
in case of mysql_fetch_array() . It return accociative array. like. row['id'] 1 row['name'] belal ; row['city'] Chatar ;
Bela Ansari


  dias   answered on£ºMar 29, 2009  0 comments

mysql_fetch_array returns the array and you can only access the database fields as array but not by their names but mysql_fetch_objewct returns the object and you can access the fields by using their names.

  maverick1   answered on£ºMar 30, 2009  0 comments

Hot Questions

Contact Us - IT-Interview