Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this code:
$var0 = 0;
$var1 = 1;
global $var0;
global $var1;
$parentQuery = $db->prepare("SELECT * FROM category WHERE parent = ? ORDER BY category");
$parentQuery->bind_param('i', $var0);
$parentQuery->execute();
$result1 = $parentQuery->get_result();
<label for="parent" class="form-label">parent:</label>
      <select class="form-select" name="parent">
        <option value=""></option>
        <?php while($p = mysqli_fetch_assoc($result1)): ?>
          <option value="<?=$p['id'];?>"<?=($result1 == $p['id']?' selected':'');?>><?=$p['category'];?></option>
        <?php endwhile; ?>
      </select>

I am getting the options correctly, but I am getting this error: "Notice: Object of class mysqli_result could not be converted to int" beside each option... I don't know why I am getting this error, how to fix it?

What I have tried:

I don't know why I am getting this error, how to fix it?
Posted
Updated 1-Mar-23 17:27pm
v3

1 solution

Read the documentation on get_result[^]. It returns a mysqli_result object, not an integer. Now go off and read the documentation on mysqli_result[^]. That mysqli_result object ends up in your $result1 variable, which you then pass to something else that is not expecting a mysqli_result object, but an integer.

That's why you're getting the error.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900