The mysql_fetch_array() function is used to find row as an associative or numeric array from a record set.
PHP mysql_fetch_array() Function Example:
The mysql_fetch_array() function is used to find row as an associative or numeric array from a record set. The mysql_fetch_array() function fetch the all matching records of results.
Example:
<?php $connection = mysql_connect("localhost","root","root"); if (!$connection) { die('PHP Mysql database connection could not connect : ' . mysql_error()); } else{ $db_name = "php_mysql"; mysql_select_db($db_name, $connection); $sql = "select * from user;"; $records = mysql_query($sql, $connection); while($rows = mysql_fetch_array($records)){ echo "User Id : " . $rows['user_id'] . "<br />"; echo "User Name : " . $rows['user_name'] . "<br />"; echo "User Email : " . $rows['user_email'] . "<br />"; echo "User Address : " . $rows['user_address'] . "<br /><br /><br />"; } } mysql_close($connection); ?>
In this example, the mysql select statement executed and return a result set records and using mysql_fetch_array() we have fetch the result.
The database 'user' table records is:
After running this example the fetch data is:
Output:
User Id : 3 User Name : Deepak User Email : deepak@rediffmail.com User Address : Noida User Id : 4 User Name : Dipali User Email : dipali@hotmail.com User Address : Guraun
[ 0 ] Comments