Name

mysql_fetch_assoc

Synopsis

array mysql_fetch_assoc (qresource query)

Returns an associative array that contains the next available row from the result set associated with the parameter query. The internal pointer associated with the result set is then incremented, so that the next call to this function will retrieve the next row. The query resource handle is returned from a prior call to mysql_query( ) or mysql_unbuffered_query( ). The function returns false when no more rows are available.

The function behaves identically to mysql_fetch_array( ) when its second parameter is set to MYSQL_ASSOC. See the description of mysql_fetch_array( ) for the limitations of associative access to query results.

Example

<?php
  $query = "SELECT people_id FROM people";
  
  $connection = mysql_connect("localhost", "fred", "shhh");
  mysql_select_db("wedding", $connection);
  
  $result = mysql_query($query, $connection);
  
  echo "Users:\n";
  
  while ($row = mysql_fetch_assoc($result))
     echo $row["people_id"] . "\n";
?>

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.