Jump to content

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/myritebook/public_html/footer.php on line 13


Nikhilesh

Recommended Posts

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/myritebook/public_html/footer.php on line 13

I am trying to fix the above error.

Please Help.

code is given below:

<?php
include 'db.php';

if ($conn) {
   echo "Database Found ";
}
else {
 die("Database connection failed");
}
$find_count=mysqli_query($conn,"SELECT * FROM count_number");


while($row=mysqli_fetch_array($find_count));
{
$current_count=$row['count'];
$new_count=$current_count+1;

try{
$sql= "UPDATE count_number SET count = '$new_count' where id=1";  
$update_count=mysqli_query ($conn,$sql);


}

catch(Exception $e){
echo 'error;'.$e->getMessage();
}
}
?>

Link to comment
Share on other sites

Yet, there it is in the manual.

The php.net function search is crap in this respect. You have to search first for the "mysqli-result" class to get to the methods

image.png.1f1ea2908dd285843edbf0579e60bc68.png

  • fetch() is mysqli-statement method
  • fetch_assoc() is a mysqli-result method.

That's the main problem with mysqli - there are two different sets of methods to process the results depending on whether you used query() or prepare().

Link to comment
Share on other sites

47 minutes ago, Barand said:

The php.net function search is crap in this respect. You have to search first for the "mysqli-result" class to get to the methods

Alternatively, you could use a search engine like Google. Searching for function names like "mysqli_fetch_array" usually lead to the corresponding PHP manual page, without needed to know the overarching class. For function names that are common to multiple programming languages, you could try "php count". More often than not, the PHP manual is in the first few links...at least it has been for me.

Minor side note @Nikhilesh: mysqli_fetch_array() gives you both an associative array and a numeric array for your data. In other words, if your database table has 2 columns (id and count), $row will contain 4 values ($row[0] - containing the ID, $row[1] - containing count, $row['id'], and $row['count']). I'm guessing that most people who use mysqli_fetch_array() never use the numeric indexes. If you don't plan on using the numeric indexes, you would be better off using mysqli_fetch_assoc() instead.

This type of advice also goes for the "*" in your query. Unless you need every column from your database table, it's better to specify the columns you actually need.

Edited by cyberRobot
fixed typo / minor edits
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.