query($sql); $count=0; if ($result->num_rows > 0) { // Array to hold the results $rows = array(); // Fetch data from each row and add it to the array while($row = $result->fetch_assoc()) { $rows[] = $row; $count = $count + 1; } $stat = "You have ". $count ." active promo code in your account."; // Output the result in JSON format header('Content-Type: application/json'); echo json_encode([$rows,"Count" => "$count","status" => "$stat"]); } else { $stat = "You don't have any active Promo Code in your Account."; echo json_encode([$rows,"Count" => "$count","status" => "$stat"]); } } // Close connection $conn->close(); ?>