Initial Commit
This commit is contained in:
46
indexes/user/getGuide.php
Normal file
46
indexes/user/getGuide.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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));
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user