File "traitement007.php"

Full Path: /home/analogde/www/MDPH/Json/traitement007.php
File size: 2.93 KB
MIME-type: text/html
Charset: utf-8

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interrogation DB</title>
    <script>
        function loadFromDB() {
            return fetch("load_mysql.php")
                .then(response => response.json())
                .then(data => {
                    console.log("plouf");
                    return data;
                })
                .catch(error => {
                    console.error("Erreur :", error);
                    showMessageModal("Une erreur est survenue lors du chargement des données.");
                });
        }

        function countValueOneInCells(cells) {
            let count = 0;
            for (let i = 0; i < cells.length; i++) {
                if (cells[i].value === "1") {
                    count++;
                }
            }
            return count;
        }

        async function displayResult() {
            let data = await loadFromDB();

            const cellsContainer = document.getElementById('cellsContainer');
            let cellsHTML = '<table border="1"><tr><th>Ligne</th><th>Nombre de "value": "1"</th></tr>';
            let jsonData = [];

            data.forEach((row, rowIndex) => {
                const cells = row.cells;
                const count = countValueOneInCells(cells);
                cellsHTML += `<tr><td>${rowIndex + 1}</td><td>${count}</td></tr>`;

                // Ajouter les informations au tableau JSON
                /*jsonData.push({
                    ligne: rowIndex + 1,
                    countValueOne: count
                });*/

                jsonData.push([rowIndex + 1, count]);


            });

            cellsHTML += '</table>';
            cellsContainer.innerHTML = cellsHTML;

            // Inverser l'ordre des premières cellules
            jsonData.reverse();


            // Créer un tableau contenant uniquement les premières cellules
            let firstCells = jsonData.map(row => row[0]);
            // Insérer un 0 à la fin de firstCells
            firstCells.push(0);

            // Créer un tableau contenant uniquement les deuxièmes cellules
            let secondCells = jsonData.map(row => row[1]);
            // Insérer un 0 en première position de secondCells
            secondCells.unshift(0);

            // Afficher les tableaux JSON dans la console
            console.log("Premières cellules :", JSON.stringify(firstCells, null, 2));
            console.log("Deuxièmes cellules :", JSON.stringify(secondCells, null, 2));
        

            
            // Afficher le tableau JSON dans la console
            //console.log(JSON.stringify(jsonData, null, 2));
        }

        window.onload = displayResult;
    </script>
</head>
<body>
    <h1>Compteur de Sous-Tableaux</h1>
    <p id="result"></p>
    <p id="countValue"></p>
    <div id="tableContainer"></div>
    <div id="cellsContainer"></div>
</body>
</html>