mysql_fetch_assoc()

It returns a row from a recordset as an associative array

MySQL table – Users

+—-+——+
| id | name |
+—-+——+
|  1 | PHP  |
|  2 | JS   |
|  3 | HTML |
|  4 | AS   |
+—-+——+

Example

<?php
mysql_connect(“localhost”, “root”, “password”) or die(mysql_error());
mysql_select_db(“database_name”);
echo “<pre>”;
$userQry = mysql_query(“SELECT * FROM users”);
while($userInfo = mysql_fetch_assoc($userQry)){
print_r($userInfo);
}
?>

Output

Array
(
[id] => 1
[name] => PHP
)
Array
(
[id] => 2
[name] => JS
)
Array
(
[id] => 3
[name] => HTML
)
Array
(
[id] => 4
[name] => AS
)