-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#228 add the script to return the most voted observations as json
- Loading branch information
1 parent
14d502f
commit 72b76f4
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php header('Content-Type: text/html; charset=UTF-8'); | ||
session_start(); | ||
include_once '../key.php'; | ||
|
||
switch (SGBD) { | ||
case 'mysql': | ||
$link = mysql_connect(DB_HOST,DB_USER,DB_PASS); | ||
mysql_select_db(DB_NAME); | ||
mysql_query("SET NAMES utf8mb4"); | ||
if (DEBUG){ | ||
error_log(date("Y-m-d H:i:s") . " - getJsonVotes.php, nb de votes à retourner : ".$_GET['nb2return']."\n", 3, LOG_FILE); | ||
} | ||
$nbObservationsToReturn = 5; | ||
if (isset($_GET['nb2return']) && is_numeric($_GET['nb2return']) && $_GET['nb2return'] > 0){ | ||
$nbObservationsToReturn = $_GET['nb2return']; | ||
} | ||
$sql = "SELECT count(*) as nb_votes, poi_poi_id, lib_subcategory, lib_pole, lib_territoire | ||
FROM `support_poi` | ||
INNER JOIN poi ON poi.id_poi = support_poi.poi_poi_id | ||
INNER JOIN pole ON poi.pole_id_pole = pole.id_pole | ||
INNER JOIN territoire ON pole.territoire_id_territoire = territoire.id_territoire | ||
INNER JOIN subcategory ON poi.subcategory_id_subcategory = subcategory.id_subcategory | ||
GROUP BY poi_poi_id | ||
ORDER BY nb_votes desc | ||
LIMIT " . $nbObservationsToReturn; | ||
|
||
$result = mysql_query($sql); | ||
$i = 0; | ||
|
||
while ($row = mysql_fetch_array($result)){ | ||
$arr[$i]['nbVotes'] = $row['nb_votes']; | ||
$arr[$i]['id_poi'] = $row['poi_poi_id']; | ||
$arr[$i]['url'] = URL."/index.php?id=".$row['poi_poi_id']; | ||
$arr[$i]['categorie'] = $row['lib_subcategory']; | ||
$arr[$i]['territoire'] = $row['lib_territoire'] . " " . $row['lib_pole']; | ||
$i++; | ||
} | ||
echo '{"statistiques":'.json_encode($arr).'}'; | ||
|
||
mysql_free_result($result); | ||
mysql_close($link); | ||
break; | ||
case 'postgresql': | ||
// TODO | ||
break; | ||
} | ||
|
||
?> |