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