I am trying to gather some information from a MySQL database and am having some issues. I can execute either of my two queries independently, but when I try to execute them both my code fails with the error Call to a member function bind_param() on a non-object in /api/boxes.php on line 20
where Line 20 is $queryFacet = $db->prepare("SELECT item_name FROM kf_facet_items WHERE id IN (SELECT facet_value_id FROM kf_box_data WHERE box_id = ?)");
Here is my code:
$query = $db->prepare("SELECT DISTINCT b.id, b.ownerID, b.transactionID, b.post_date, b.description FROM kf_boxes b JOIN kf_box_data d ON b.id = d.box_id");
$query->execute();
$query->bind_result($id, $owner, $transactionID, $post_date, $description);
while ($query->fetch()) {
$result['id'] = $id;
$result['transaction'] = $transactionID;
$result['post_date'] = $post_date;
$result['description'] = $description;
$queryFacet = $db->prepare("SELECT item_name FROM kf_facet_items WHERE id IN (SELECT facet_value_id FROM kf_box_data WHERE box_id = ?)");
$queryFacet->bind_param('s',$id);
$queryFacet->execute();
$queryFacet->bind_result($item_name);
while ($queryFacet->fetch()) {
$facets['name'] = $item_name;
$result['facets'] = $facets;
}
$output[] = $result;
}
Anyone have any ideas on what is causing this and more importantly, how to solve it?