File "query002.php"
Full Path: /home/analogde/www/Design/Dev tableau/query002.php
File size: 1.29 KB
MIME-type: text/x-php
Charset: utf-8
<?php
$host = "analogdepat.mysql.db";
$dbname = "analogdepat";
$username = "analogdepat";
$password = "Un92pac007";
$table = "json_data";
// Connexion
$conn = new mysqli($host, $username, $password, $dbname);
// Vérifier la connexion
if ($conn->connect_error) {
die("Connexion échouée : " . $conn->connect_error);
} else {
$sql = "SELECT * FROM $table";
$result = $conn->query($sql);
// Vérifier si la requête a retourné des résultats
if ($result->num_rows > 0) {
echo '<select name="dates" id="dates" onchange="showJsonData()">';
// Afficher les données de chaque ligne dans une option de la combo box
while ($row = $result->fetch_assoc()) {
echo '<option value=\'' . htmlspecialchars(json_encode($row["data_json"]), ENT_QUOTES, 'UTF-8') . '\'>' . $row["created_at"] . '</option>';
}
echo '</select>';
echo '<div id="json-output"></div>';
} else {
echo "0 résultats";
}
// Fermer la connexion
$conn->close();
}
?>
<script>
function showJsonData() {
var select = document.getElementById('dates');
var jsonData = select.options[select.selectedIndex].value;
document.getElementById('json-output').innerText = JSON.parse(jsonData);
}
</script>