query($sql); $output = array('data' => array()); if($result->num_rows > 0) { $paymentStatus = ""; $x = 1; while($row = $result->fetch_array()) { $orderId = $row[0]; $countOrderItemSql = "SELECT count(*) FROM order_item WHERE order_id = $orderId"; $itemCountResult = $connect->query($countOrderItemSql); $itemCountRow = $itemCountResult->fetch_row(); // active if($row[4] == 1) { $paymentStatus = ""; } else if($row[4] == 2) { $paymentStatus = ""; } else { $paymentStatus = ""; } // /else $button = '
'; $output['data'][] = array( // image $x, // order date $row[1], // client name $row[2], // client contact $row[3], $itemCountRow, $paymentStatus, // button $button ); $x++; } // /while }// if num_rows $connect->close(); echo json_encode($output);