0

Every job has its processes stored in a separate table, connected by the foreign key.

I want to select ids of jobs and then loop through processes by some criteria. But it returns me an error when I want to run another SQL query inside while loop.

Uncaught Error: Call to a member function bind_param() on bool

I checked the query in PHPMyAdmin and it worked.

$query=$conn->prepare("SELECT * FROM jobs");
$query->execute();
$result=$query->get_result();
$query->close();

while($row = $result->fetch_assoc()) {
    $id=(int)$row['id'];

    $query2=$conn->prepare("SELECT *FROM processes WHERE job_id=?");
    $query2->bind_param('i',$id);
    $query2->execute();
}

I know that the same job can be done in another way, but I want to know where is the error or what I am doing wrong here.

Thanks!

  • Does this answer your question? [Why is mysqli giving a "Commands out of sync" error?](https://stackoverflow.com/questions/3632075/why-is-mysqli-giving-a-commands-out-of-sync-error) – El_Vanja Mar 23 '20 at 00:05
  • 1
    Also, here's a thorough [tutorial](https://stackoverflow.com/a/22662582/4205384) on debugging db related problems. It's a handy tool for any future problems you might run into. – El_Vanja Mar 23 '20 at 00:06

0 Answers0