-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathat_get_all_point_for_map.php
43 lines (33 loc) · 1.48 KB
/
at_get_all_point_for_map.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
<?php
function at_get_all_point() {
require_once('at_config.php');
$db = mysqli_connect(SERVERNAME, USERNAME, PASSWORD, DATABASE);
if(!$db)
return array('success'=>-1, 'message'=>'Database connexion error');
mysqli_set_charset($db,"utf8");
$points = mysqli_query($db,
"SELECT points.id,points.name,towns.name as ville_name, towns.wilaya as wilaya, points.type, points.description,longitude,latitude FROM points,towns
Where points.town_id = towns.id");
if(!$points)
return array('success'=>-1, 'message'=>'Database retrieve error');
$tmp_points = array();
while($point = mysqli_fetch_assoc($points)) {
$point_rank = mysqli_query($db, "SELECT ROUND(SUM(rating) / COUNT(rating),1) as point_rating FROM opinions WHERE point_id = '$point[id]'");
if(!$point_rank){
$point['point_rating'] = '0.0';
}else {
$point_rating = mysqli_fetch_assoc($point_rank)['point_rating'];
if ( $point_rating != ''){
$point['point_rating'] = $point_rating;
}else{
$point['point_rating'] = '0.0';
}
}
array_push($tmp_points, $point);
}
mysqli_close($db);
return array('success'=>1, 'message'=>'Points retrieved successfully', 'points'=>$tmp_points);
}
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['target']) && $_POST['target'] == 'external')
echo json_encode(at_get_all_point());
?>