0 and ohc_type_id = '" . $_SESSION['current_ohcttype'] . "' order by expiry_date asc limit 1"; if (!$result_stock = mysqli_query($conn, $stock)) { error_log("error in stock " . $stock); } else { $row_stock = mysqli_fetch_assoc($result_stock); $item_id = $row_salt['item_id']; $item_name = getFieldFromTable('item_name', 'tbl_items', 'item_id', $item_id); $is_prescribed = getFieldFromTable('is_prescription','tbl_items','item_id',$item_id); if ($row_stock['qty'] == null) { $item_ids[] = array( 'item_name' => $item_name, 'item_id' => $item_id, 'is_prescribed' => $is_prescribed, 'qty' => 0 ); } else { $item_ids[] = array( 'item_name' => $item_name, 'item_id' => $item_id, 'is_prescribed' => $is_prescribed, 'qty' => $row_stock['qty'] ); } } } } error_log("data " . print_r($item_ids, true)); } echo json_encode($item_ids);