47 lines
1.1 KiB
PHP
47 lines
1.1 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 user_guide WHERE username 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);
|
|
$start=microtime(true);
|
|
// search current page data
|
|
$sql = "SELECT
|
|
user_guide.u_id,
|
|
user_guide.username,
|
|
guide_type.guide_type_name AS typename,
|
|
user_guide.rating,
|
|
user_guide.fee,
|
|
user_guide.descrip
|
|
FROM
|
|
user_guide JOIN guide_type ON user_guide.guide_type_id=guide_type.guide_type_id
|
|
WHERE username 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()) {
|
|
$data[] = $row;
|
|
}
|
|
} else {
|
|
$data[] = "No result";
|
|
}
|
|
|
|
echo json_encode(array("data" => $data, "total_pages" => $total_pages,"time"=>$execution_time));
|
|
?>
|
|
|
|
|
|
|
|
|