top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between mysql_fetch_array() vs mysql_fetch_assoc() ?

0 votes
238 views
What is the difference between mysql_fetch_array() vs mysql_fetch_assoc() ?
posted Jul 9, 2014 by Sidharth Malhotra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Difference between mysql_fetch_array() vs mysql_fetch_assoc()
mysql_fetch_array()

$rows = mysql_fetch_array( "select name, address from people");

Means you then get each of the row results as a straight array, meaning you dont necessarily need to know in advance the order elements arrive via the select.

foreach( $rows as $row )
echo $row[0] . ' lives at ' . $row[1] ;.

$rows = mysql_fetch_assoc()

$rows = mysql_fetch_assoc( "select name, address from people" );

Means you then get each of the row results as a named array elements, an associative array.

foreach( $rows as $row )
echo $row['name'] . ' lives at ' . $row['address'];

Which is now dependent on you knowing what the result columns are named.

answer Jul 11, 2014 by Vrije Mani Upadhyay
...