PHP : mysql_fetch_array() function
Description
The mysql_fetch_array() is used to retrieve a row of data as an array from a MySQL result handle.
Version
(PHP 4 and above)
Syntax
mysql_fetch_array(result, result_type)
Parameters
| Name | Description | Required/ Optional | Type |
|---|---|---|---|
| result | Refers to the resource return by a valid mysql query (calling by mysql_query() function). | Required | Resource |
| result_type | The type of the result is an array. Possible values : MYSQL_ASSOC - Associative array MYSQL_NUM - Numeric array MYSQL_BOTH - Both associative and numeric array Default : MYSQL_BOTH |
Optional | Integer |
Return value
An array containing one row of data, or FALSE if there are no more rows.
Value Type : Array.
Example :
<?php
$con = mysql_connect("localhost", "root", "mypass") or
die("Could not connect: " . mysql_error());
mysql_select_db("tutorials");
$result = mysql_query("select * from tutorials");
echo "<table border='1' style='border-collapse: collapse'>";
echo "<th>Name of theTutorial</th><th>Pages</th><th>Examples</th><th>Author</th>";
while ($row = mysql_fetch_array($result))
{
echo"<tr><td>".$row['name']."</td><td>".$row['no_of_pages']."</td><td>".$row['no_of_examples']."</td><td>".$row['author']."</td></tr>";
}
echo "</table>";
mysql_close($con);
?>
Output :
| Name of the Tutorial | Pages | Examples | Author |
|---|---|---|---|
| html | 1000 | 1000 | rd |
| css | 300 | 250 | rd |
| sql | 500 | 500 | bc |
| mysql | 500 | 500 | bc |
| javascript | 800 | 800 | rg |
| php | 700 | 700 | rg |
See also

