Jump to content

Warning: Mysqli_Fetch_Array() Expects Parameter 1 To Be Mysqli_Result, Boolean


designanddev

Recommended Posts

Hi i have this function below....

biut i keep geting this warning message Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean

 

i get this message when i run the function and set it $id, im not sure if the isset in this query is actually workin

could someone please help.

 

Kind Regards

 

 

function get_posts($id = null, $cat_id = null){
global $dbc;
$posts = array();

$query = "SELECT b.message as bmsg, b.ID as bid, b.subject, b.post_on, c.ID, c.blog_id, c.message as mgs FROM blog as b LEFT JOIN comments as c ON b.ID = c.blog_id GROUP BY bmsg";
if(isset($id)){
$query .= "WHERE b.ID = '$id'";
}
$query = mysqli_query($dbc ,$query);

while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$posts[] = $row;

}
return $posts;
}

Go into the database, phpmyadmin or whatever it is, and run the query directly with a value for $id that you know should work. When you get that error usually it means that mysql has returned something that isn't a query result so php doesn't know how to handle it.

how would i check the if(isset($id)) in SQL query?

 

$query = "SELECT b.message as bmsg, b.ID as bid, b.subject, b.post_on, c.ID, c.blog_id, c.message as mgs FROM blog as b LEFT JOIN comments as c ON b.ID = c.blog_id GROUP BY bmsg";
if(isset($id)){
$query .= "WHERE b.ID = '$id'";
}

The syntax of your query statement is incorrect. The WHERE clause does not go on the end. The following is the basic SELECT query syntax definition (the elements, when present, must be in the order shown) -

 

SELECT
   [ALL | DISTINCT | DISTINCTROW ]
     [HIGH_PRIORITY]
     [sTRAIGHT_JOIN]
     [sql_SMALL_RESULT] [sql_BIG_RESULT] [sql_BUFFER_RESULT]
     [sql_CACHE | SQL_NO_CACHE] [sql_CALC_FOUND_ROWS]
   [i]select_expr[/i] [, [i]select_expr[/i] ...]
   [FROM [i]table_references[/i]
   [WHERE [i]where_condition[/i]]
   [GROUP BY {[i]col_name[/i] | [i]expr[/i] | [i]position[/i]}
     [ASC | DESC], ... [WITH ROLLUP]]
   [HAVING [i]where_condition[/i]]
   [ORDER BY {[i]col_name[/i] | [i]expr[/i] | [i]position[/i]}
     [ASC | DESC], ...]
   [LIMIT {[[i]offset[/i],] [i]row_count[/i] | [i]row_count[/i] OFFSET [i]offset[/i]}]
   [PROCEDURE [i]procedure_name[/i]([i]argument_list[/i])]
   [iNTO OUTFILE '[i]file_name[/i]'
       [CHARACTER SET [i]charset_name[/i]]
       [i]export_options[/i]
     | INTO DUMPFILE '[i]file_name[/i]'
     | INTO [i]var_name[/i] [, [i]var_name[/i]]]
   [FOR UPDATE | LOCK IN SHARE MODE]]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.