Initial Commit
This commit is contained in:
58
indexes/seller/getAttraction.php
Normal file
58
indexes/seller/getAttraction.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['usertype']) || $_SESSION['usertype'] !== "seller") {
|
||||
header('Location: ../../index.php');
|
||||
exit();
|
||||
}
|
||||
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
|
||||
|
||||
$seller_id = $_SESSION['uid'];
|
||||
|
||||
$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.seller_id = $seller_id AND attraction.name LIKE '%" . $q . "%'
|
||||
";
|
||||
|
||||
$result = $conn->query($sql);
|
||||
$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));
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user