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
| <?php
$sql =
<<<'SQL'
SELECT
h_lieu,
h_lat,
h_long,
h_dt2,
h_ev
FROM
historique
WHERE
h_id = :theme
ORDER BY
h_lieu,
h_lat,
h_long
SQL;
/** @var PDOStatement */
$stmt = $connexion->prepare($sql);
// je considère que h_id est un entier
$stmt->bindParam(':theme', $theme1, PDO::PARAM_INT);
//Création des variables
$i = 0;
$keys = array();
$evts = array();
$titres = array();
$tableauLieux = '';
// la clé sert à fixer un chiffre à chaque mot
foreach ($theme as $cle1 => $theme1) {
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$key = "{$row['h_lieu']};{$row['h_lat']};{$row['h_long']}";
$id = array_search($key, $keys, true);
if ($id === false) {
$id = $i++;
$keys[$id] = $key;
$data[$id] = array($row['h_lieu'], $row['h_lat'], $row['h_long']);
}
$evts[$id][] = $row['h_dt2'].' '.$row['h_ev'];// Concatenation dates et événements
}
}
foreach($keys as $id => $key) {
$titres[] =
'"'.$data[$id][0].'"'
.','.$data[$id][1]
.','.$data[$id][2]
.',"'.implode('<br />', $evts[$id]).'"'
.'';
}
$titre = array ();
foreach($titres as $element) {
if ($tableauLieux !== '') {
$tableauLieux.=',';
}
$tableauLieux .= '['.$element.']';
echo $tableauLieux; // affichera $prenoms[0], $prenoms[1] etc.
} |
Partager