-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_rest.php
153 lines (143 loc) · 6.68 KB
/
all_rest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
session_start();
include 'templates/header.php';
function addcss(){
echo '<link rel="stylesheet" type="text/css" href="styles/all_rest_nav.css">';
echo '<link rel="stylesheet" type="text/css" href="styles/grid.css">';
echo '<script src="scripts/location.js"></script>';
}
include 'templates/navbar.php';
if($_GET['sort_by'])
$sort_by=$_GET['sort_by'];
else
$sort_by='none';
?>
<div class="container" id="container">
<div class="row" id="outer-row">
<div class="col-sm-2 sticky-top" id="column-left">
<div class="sticky-top">
<ul class="nav nav-pills flex-column bg-light">
<li class="nav-brand bg-dark" id="nav-head">Sortby</li>
<li class="nav-item" id="side-nav-item"><a class="nav-link" id="side-nav-link" href="all_rest.php?sort_by=rating">Rating</a></li>
<li class="nav-item" id="side-nav-item"><a class="nav-link" onclick="getLocation()" id="side-nav-link" href="all_rest.php?sort_by=distance">Distance</a></li>
<li class="nav-item" id="sidenav-item"><a class="nav-link" id="side-nav-link" href="all_rest.php?sort_by=cost">Aproxx Cost</a></li>
</ul>
<!--
<div id="side-nav">
<div id="side-nav-item" style="background-color:#808080;border-radius:10px;">
<p>Sort By</p>
</div>
<a href="all_rest.php?sort_by=rating" id="side-nav-link">
<div id="side-nav-item">
Rating
</div>
</a>
<a href="all_rest.php?sort_by=distance" id="side-nav-link" onclick="getLocation()">
<div id="side-nav-item">
Distance
</div>
</a>
<a href="all_rest.php?sort_by=cost" id="side-nav-link">
<div id="side-nav-item">
Aproxx Cost
</div>
</a>
</div>
-->
</div>
</div>
<div class="col-sm-9" id = "column-right">
<div class="row" id="inner-row">
<?php
include "templates/db-con.php";
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if($sort_by == "distance"){
$sql = "SELECT rest_id,latitude,longitude from rest";
$result = mysqli_query($conn, $sql);
if(!$result){
die("QUERY FAILED ".mysqli_error($conn));
}
else{
$distance = array();
while($row = mysqli_fetch_assoc($result)){
$distance[$row['rest_id']] = sqrt(pow($row['latitude']-$_SESSION['latitude'],2)+pow($row['longitude']-$_SESSION['longitude'],2));
}
asort($distance);
$keys = array_keys($distance);
for($i=0;$i<(sizeof($distance));$i++){
$sql = "SELECT rest_id,rating,rest_name,cost from rest where rest_id= $keys[$i];";
$result = mysqli_query($conn, $sql);
if(!$result){
die("QUERY FAILED ".mysqli_error($conn));
}
else{
$row = mysqli_fetch_assoc($result);
$id = $row['rest_id'];
$name = $row['rest_name'];
$cost = $row['cost'];
$rating = $row['rating'];
$i++;
?>
<div class="col-sm-3" id = "hotel" >
<div class="thumbnail">
<a id="rest-link" href="rest_details.php?rest_id=<?php echo $id ?>">
<img src="images/<?php echo abs(crc32($id))%30; ?>.jpg" alt="<?php echo "$name"?>" style="width:100%; height: 130px;">
<div class="caption">
<div id="rest-name">
<p><?php echo $name ?></p>
</div>
<div id='rate-cost'>
<span id="cost"><?php echo "Aproxx: ₹".$cost ?></span>
<span class="fa fa-star" id="star"></span>
<span id="rating"><?php echo $rating ?></span>
</div>
</div>
</a>
</div>
</div>
<?php
}
}
}
}
elseif($sort_by == "none")
$sql = "SELECT rest_id,rating,rest_name,cost from rest;";
elseif($sort_by == "rating")
$sql = "SELECT rest_id,rating,rest_name,cost from rest ORDER BY rating DESC;";
elseif($sort_by == "cost")
$sql = "SELECT rest_id,rating,rest_name,cost from rest ORDER BY cost;";
$result = mysqli_query($conn, $sql);
if(!$result){
die("QUERY FAILED ".mysqli_error($conn));
}
else{
while($row = mysqli_fetch_assoc($result)){
$id = $row['rest_id'];
$name = $row['rest_name'];
$cost = $row['cost'];
$rating = $row['rating'];
?>
<div class="col-sm-3" id = "hotel" >
<div class="thumbnail">
<a id="rest-link" href="rest_details.php?rest_id=<?php echo $id ?>">
<img src="images/<?php echo abs(crc32($id))%30; ?>.jpg" alt="<?php echo "$name"?>" style="width:100%; height: 130px;">
<div class="caption">
<div id="rest-name">
<p><?php echo $name ?></p>
</div>
<div id='rate-cost'>
<span id="cost"><?php echo "Aproxx: ₹".$cost ?></span>
<span class="fa fa-star" id="star"></span>
<span id="rating"><?php echo $rating ?></span>
</div>
</div>
</a>
</div>
</div>
<?php
}
}
include 'templates/footer.php';
?>