<!DOCTYPE html>
<html>

    <head>

    </head>

    <body>

        <?php
        $q = intval($_GET['q']);
        // connexion a la base
        $db = mysqli_connect('localhost', 'root', 'm148r43a9Y@%Z','smartpassTest2');
           
        if(!$db){
            die("Erreur de connection :" .mysqli_error($db));
        }

        // selection de la base 
        mysqli_select_db($db, "ajax_demo");
        //Requete SQL
        $strSQL = "SELECT * FROM Parcours WHERE id = '".$q."'";
        $result = mysqli_query($db, $strSQL);

        if(mysqli_num_rows($result) == 0){
          echo "<p>Aucun champ ! '".$q."' </p>";
        }

        while($resultat = mysqli_fetch_array($result)){
            echo "<h1> Le parcours : ". $resultat["Titre"] ." est le numéro : " . $resultat["id"] . "</h1>";
            $point = $resultat["idPoints"];
            $decoupe = explode(",", $point);

            echo "<div id = 'latLonPoints' style='display:none;'>";
            for($i = 0; $i < count($decoupe) ; $i++){
                echo "<br/>";
                $strSQL2 = "SELECT * FROM InformationsGenerales WHERE id = '".$decoupe[$i]."'";
                $result2 = mysqli_query($db, $strSQL2);
                    
                while($resultat2 = mysqli_fetch_array($result2)){
                    echo "<p id=". $resultat2["id"] .">||". $resultat2["Lattitude"] ."||". $resultat2["Longitude"] ."||</p>";
                    echo "<br/>";
                }
            }
            echo "</div>";

            echo "<div id = 'latLonPoints' style='display:none;'>";
            for($i = 0; $i < count($decoupe) ; $i++){
                echo "<br/>";
                $strSQL3 = "SELECT * FROM DescriptionGenerale WHERE id = '".$decoupe[$i]."'";
                $result3 = mysqli_query($db, $strSQL3);
                    
                while($resultat3 = mysqli_fetch_array($result3)){
                    echo "<p id = ". $resultat3["id"] ." > ||". utf8_encode($resultat3["Titre"]) ."||". utf8_encode($resultat3["Soustitre"]) ."||</p>";
                    echo "<br/>";
                }
            }
            echo "</div>";

        }//while
        mysqli_close($db);
        ?>
    </body>
</html>