php - warning problem: expects parameter 1 to be mysqli_result -


possible duplicate:
mysql_fetch_array() expects parameter 1 resource, boolean given in select

i following warning listed below , wondering how fix it

warning: mysqli_fetch_array() expects parameter 1 mysqli_result, boolean given on line 65 

the code around section of php code listed below. can list full code if needed.

// function retrieve average , votes function getratingtext(){     $dbc = mysqli_connect ("localhost", "root", "", "sitename");     $sql1 = "select count(*)               articles_grades               users_articles_id = '$page'";      $result = mysqli_query($dbc,$sql1);     $total_ratings = mysqli_fetch_array($result);      $sql2 = "select count(*)               grades               join grades on grades.id = articles_grades.grade_id              articles_grades.users_articles_id = '$page'";      $result = mysqli_query($dbc,$sql2);     $total_rating_points = mysqli_fetch_array($result);     if (!empty($total_rating_points) && !empty($total_ratings)){         $avg = (round($total_rating_points / $total_ratings,1));         $votes = $total_ratings;         echo $avg . "/10  (" . $votes . " votes cast)";     } else {         echo '(no votes cast)';     } } 

mysqli_query() returns false if there error in query. should test it...

/* select queries return resultset */ if ($result = mysqli_query($dbc, "select name city limit 10")) {     printf("select returned %d rows.\n", $result->num_rows);      /* free result set */     $result->close(); } 

see link mysqli_query reference http://php.net/manual/en/mysqli.query.php


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -