Initial Commit
This commit is contained in:
62
indexes/seller/getFood.php
Normal file
62
indexes/seller/getFood.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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 restaurant 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);
|
||||
|
||||
$seller_id = $_SESSION['uid'];
|
||||
|
||||
// search current page data
|
||||
$sql = "SELECT
|
||||
restaurant.restaurant_id,
|
||||
restaurant.name AS rname,
|
||||
cities.name AS cname,
|
||||
restaurant.location,
|
||||
restaurant.open_day,
|
||||
restaurant.close_day,
|
||||
restaurant.open_time,
|
||||
restaurant.close_time,
|
||||
restaurant.rating,
|
||||
restaurant_style.restaurant_style_name,
|
||||
restaurant.descrip,
|
||||
restaurant.fee,
|
||||
restaurant_style.restaurant_style_image AS image
|
||||
FROM
|
||||
restaurant
|
||||
JOIN
|
||||
cities ON restaurant.city_id = cities.id
|
||||
JOIN
|
||||
restaurant_style ON restaurant.restaurant_style_id = restaurant_style.restaurant_style_id
|
||||
WHERE restaurant.seller_id = $seller_id AND restaurant.name LIKE '%".$q."%';";
|
||||
$result = $conn->query($sql);
|
||||
$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));
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user