Initial Commit
This commit is contained in:
54
indexes/user/getHotel.php
Normal file
54
indexes/user/getHotel.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
include "../ConnectDB.php";
|
||||
$q = $_REQUEST["myinput"];
|
||||
$state = $_REQUEST["state"];
|
||||
$city = $_REQUEST["city"];
|
||||
$hotel_type = $_REQUEST["hotel_type"];
|
||||
$page = isset($_REQUEST["page"]) ? $_REQUEST["page"] : 1;
|
||||
$limit = 3;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$result_count = $conn->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));
|
||||
?>
|
||||
Reference in New Issue
Block a user