query("SELECT COUNT(*) AS count FROM hotel JOIN cities ON hotel.city_id = cities.id JOIN states ON cities.state_id=states.id JOIN hotel_type ON hotel.hotel_type_id = hotel_type.hotel_type_id WHERE hotel.name LIKE '%$q%' AND states.id=$state AND cities.id=$city AND hotel_type.hotel_type_id=$hotel_type"); $row_count = $result_count->fetch_assoc(); $count = $row_count["count"]; $total_pages = ceil($count / $limit); $start=microtime(true); $sql = "SELECT hotel.hotel_id, hotel.name AS hname, cities.name AS cname, hotel_type.hotel_type_name, hotel.rating, hotel_type.hotel_type_image AS image FROM hotel JOIN cities ON hotel.city_id = cities.id JOIN states ON cities.state_id=states.id JOIN hotel_type ON hotel.hotel_type_id = hotel_type.hotel_type_id WHERE hotel.name LIKE '%$q%' AND states.id=$state AND cities.id=$city AND hotel_type.hotel_type_id=$hotel_type LIMIT $limit OFFSET $offset"; $result = $conn->query($sql); $end = microtime(true); $execution_time = $end - $start; $data = array(); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $row["image"] = base64_encode($row["image"]); $data[] = $row; } } else { $data[] = "No result"; } echo json_encode(array("data" => $data, "total_pages" => $total_pages,"time"=>$execution_time)); ?>