when you pass a query result to mysql_fetch_array, it should contain some data otherwise it will returns a warning like "mysql_fetch_array() expects parameter 1 to be resource (or mysqli_result), boolean given"

mysql_query  function will return a result when we execute a query. If there is no data availabe in database, mysql_query will return FALSE.

In such scenario if the output of mysql_query directly passed to mysql_fetch_array then it will show a warning mysql_fetch_array() expects parameter 1 to be resource (or mysqli_result), boolean given.

So it always better to validate the query result before passing it to further process. Following example shows that.
 
<?php
$query='select * from users';
$result=mysql_query($query);

if(!$result){
    die('No records found');
}

while($row = mysql_fetch_array($result))
{
    echo $row['name'];
}
?>

 


Comments (0)
Leave a Comment

loader Posting your comment...