Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between mysql_fetch_array() and mysql_fetch_row()

 
Deepthi Tanguturi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difference between mysql_fetch_array() and mysql_fetch_row()
 
Nick Charles
Ranch Hand
Posts: 71
Linux PHP Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mysql_fetch_row is the same as mysql_fetch_array with MYSQL_NUM. That is, you get an array with a numeric index.

However, with mysql_fetch_array you can also specify MYSQL_ASSOC, in which case the array is indexed by the column names. And then there is MYSQL_BOTH where you can use either a numeric or column name index.

Using the links Matthew provide, look at how the examples differ for the two functions.
 
John David Peter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mysql_fetch_array(): It return values both an associative and numeric array
example:
<table>
<th>Game_ID</th><th>Category</th><th>Title</th>
<?php
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('new') or die(mysql_error());
$query=mysql_query('select * from table1') or die(mysql_error());
while($res=mysql_fetch_array($query, MYSQL_NUM))
{
echo'<tr><td>'.$res[0].'</td><td>'.$res[1].'</td><td>'.$res[2].'</td></tr>';
}
echo'<table>';
?>


Reference:mysql_fetch_array

mysql_fetch_row():
It return values as numeric array
example:
<table>
<th>Game_ID</th><th>Category</th><th>Title</th>
<?php
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('new') or die(mysql_error());
$query=mysql_query('select * from table1') or die(mysql_error());
while($res=mysql_fetch_row($query))
{
echo'<tr><td>'.$res[0].'</td><td>'.$res[1].'</td><td>'.$res[2].'</td></tr>';
}
echo'<table>';
?>


Reference:mysql_fetch_row
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic