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; } if($count > 1){ $prefix ='s'; }else{ $prefix =''; } $stat = "You have ". $count . " registered vehicle".$prefix." in your account. "; // Output the result in JSON format header('Content-Type: application/json'); echo json_encode([$rows,"Count" => "$count","status" => "$stat"]); } else { $stat = "There is no vehicle registered under this account. Click Add Car button to register your vehicle."; echo json_encode([$rows,"Count" => "$count","status" => "$stat"]); } } // Close connection $conn->close(); ?>