forked from codingCAT-jacky/DataBase_final
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect_hotel.php
More file actions
27 lines (23 loc) · 1.01 KB
/
Copy pathselect_hotel.php
File metadata and controls
27 lines (23 loc) · 1.01 KB
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
<?php
include "db_conn.php";
$hotelName = $_GET['HotelName'];
$query = ("select * from hotel where HotelName = ?");
$stmt = $db->prepare($query);
$error= $stmt->execute(array($hotelName));
$result = $stmt->fetchAll();
//以上寫法是為了防止「sql injection」
// $HotelArray = array();
if(count($result)==0){
echo "no Hotel";
}
else{
for($i=0; $i<count($result); $i++){
$HotelObject = array( 'HotelName' => $result[$i]['HotelName'], 'Description' => $result[$i]['Description'],
'Address' => $result[$i]['Address'], 'Zone' => $result[$i]['Zone'],
'StarNum' => $result[$i]['StarNum'], 'Count' => $result[$i]['Count'], 'PhotoURL' => $result[$i]['PhotoURL']);
$HotelArray[] = $HotelObject;
}
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode($HotelArray, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
?>