File "combo_db_01.php"

Full Path: /home/analogde/www/ONSEMI/New folder/combo_db_01.php
File size: 1.94 KB
MIME-type: text/x-php
Charset: utf-8

<?php

$host = "analogdepat.mysql.db";   
$dbname = "analogdepat";
$username = "analogdepat"; 	   
$password = "Un92pac007";	


$conn = new mysqli($host, $username, $password, $dbname);

// Vérification de la connexion
if ($conn->connect_error) {
    die("Erreur de connexion : " . $conn->connect_error);
}

// Récupération des données de la table
$sql = "SELECT id, column_name, created_at FROM table_DB_planning";
$result = $conn->query($sql);

$entries = [];
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $entries[] = $row;
    }
}

// Fermeture de la connexion
$conn->close();
?>


<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Combobox avec PHP</title>
    <script>
        function displayJson() {
            const select = document.getElementById("comboBox");
            const jsonDisplay = document.getElementById("jsonDisplay");
            const selectedValue = select.value;

            if (selectedValue) {
                jsonDisplay.textContent = "ID de l'élément sélectionné : " + selectedValue;
            } else {
                jsonDisplay.textContent = "Sélectionnez un élément pour afficher son ID.";
            }
        }
    </script>
</head>
<body>
    <h1>Combobox avec affichage des données</h1>

    <label for="comboBox">Choisissez un titre :</label>
    <select id="comboBox" onchange="displayJson()">
        <option value="">-- Sélectionnez --</option>
        <?php foreach ($entries as $entry): ?>
            <option value="<?= htmlspecialchars($entry['column_name']) ?>">
                <?= htmlspecialchars($entry['id']) ?>
            </option>
        <?php endforeach; ?>
    </select>

    <h2>Données associées</h2>
    <pre id="jsonDisplay">Sélectionnez un élément pour afficher son ID.</pre>
</body>
</html>