Answer the question
In order to leave comments, you need to log in
Why after mysqli:fetch it is not possible to use another mysqli:fetch, otherwise an error?
I'm trying to nest one mysqli query into another (no other way). After the first request, I start executing the second one and get an error:
Fatal error: Call to a member function fetch_assoc() on a non-object in C:\Sites\home\jarga-land.ru\www\backend\admin_product_AE.php on line 45
$results = $mysqli->prepare("SELECT category.name_category, product.* FROM `category` INNER JOIN `product` ON id_cat = category_id AND product.id = $prod_id");
$results->execute(); //Execute prepared Query
$results->bind_result($cat_name, $id, $title, $description, $full_description, $price, $image, $category_id);
$results->fetch();
//bla bla bla html code
<?php
//for($sg=0;$sg<5;$sg++){
$q = $mysqli->query("SELECT * FROM `category`");
while($all_cat=$q->fetch_assoc()) // Call to a member function fetch_assoc() on a non-object in ...
{
$cur_cat_name=$all_cat['name_category'];
//echo $id_cat;
if($all_cat['id_cat']!=$category_id)
{
echo '<option value="'.$all_cat['id_cat'].'">'.$cur_cat_name.'</option>';
}
else echo '<option selected value="'.$all_cat['id_cat'].'">'.$cur_cat_name.'</option>';
}
?>
Answer the question
In order to leave comments, you need to log in
You should think about writing code more competently.
Your $mysqli->query returns FALSE and you don't handle this situation in any way - php.net/manual/ru/mysqli.query.php . Read the documentation and look at the examples, there is a solution to the problem like you have.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question