53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
include "../ConnectDB.php";
|
|
$q = $_REQUEST["q"];
|
|
$page = isset($_REQUEST["page"]) ? $_REQUEST["page"] : 1;
|
|
$limit = 3;
|
|
$offset = ($page - 1) * $limit;
|
|
|
|
// find the total corresponding message
|
|
$sql_count = "SELECT COUNT(*) AS count FROM attraction WHERE name LIKE '%".$q."%'";
|
|
$result_count = $conn->query($sql_count);
|
|
$row_count = $result_count->fetch_assoc();
|
|
$count = $row_count["count"];
|
|
|
|
// calculate the total page number
|
|
$total_pages = ceil($count / $limit);
|
|
|
|
// search current page data
|
|
$start=microtime(true);
|
|
$sql = "SELECT
|
|
attraction.attraction_id,
|
|
attraction.name AS aname,
|
|
cities.name AS cname,
|
|
attraction.rating,
|
|
attraction.descrip,
|
|
attraction.price,
|
|
attraction_type.attraction_type_image
|
|
FROM
|
|
attraction
|
|
JOIN
|
|
cities ON attraction.city_id = cities.id
|
|
JOIN
|
|
attraction_type ON attraction.attraction_type_id = attraction_type.attraction_type_id
|
|
WHERE attraction.name LIKE '%".$q."%' 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["attraction_type_image"] = base64_encode($row["attraction_type_image"]);
|
|
$data[] = $row;
|
|
}
|
|
} else {
|
|
$data[] = "No result";
|
|
}
|
|
|
|
echo json_encode(array("data" => $data, "total_pages" => $total_pages,"time"=>$execution_time));
|
|
?>
|
|
|
|
|
|
|
|
|