return $result; } function get_stock($type_id) { $sql = "SELECT * FROM `tbl_product_stock` WHERE `type_id`= '{$type_id}' ORDER BY `stock_name`"; $query = $this->conn->query($sql); $row = array(); while ($result = $query->fetch_object()) { array_push($row, $result); } return $row; } } $_ajax = new AJAX(); $ajax_type_id = filter_var($_POST['type_id'], FILTER_SANITIZE_EMAIL); $count = $_ajax->count_stock($ajax_type_id); if ($count->rows > 0) { $data = $_ajax->get_stock($ajax_type_id); echo '<label class="control-label col-xs-3">Stock Name</label>'; echo '<div class="col-xs-9">'; echo '<select name="type" id="id-modal-stock" class="form-control">'; foreach ($data as $data) { echo '<option '; if ($data->stock_quantity == 0) { echo 'disabled="disabled"'; } echo ' value="' . $data->stock_id . '" data-total="' . $data->stock_quantity . '">' . $data->stock_name . '</option>'; } echo '</select>'; } else { /* --- NO RECORDS FOUND ---*/