I'm currently trying to append all the questions from questions.json
to my main PHP
page and I would like to do it dynamically.
I've searched for tutorials and when I copy-paste the code it works, but when I change it with mine, it doesn't. I'm still a newbie who is learning, so please don't throw at me bunch of complex code. Much appreciated !
questions.json:
{"Theme": "Montpellier",
"url" : "correction.php",
"questions": [
{"question": " Combien sommes-nous?", "reponses": [{"choix": "3"},{"choix": "43"},{"choix": "5"}]},
{"question": "Selon sa demographie quelle est le classement de Montpellier?","reponses": [{"choix": "8eme"},{"choix": "5eme"},{"choix": "2eme"}]},
{"question": "Autour de quelle date la fête des lumières ce deroulle-t-elle? ","reponses": [{"choix": "31 Novembre"},{"choix": "6 Septembre"},{"choix": "18 Juillet"}]},
{"question": " Combien de lignes de trameway y'a t-il à Montpellier?","reponses": [{"choix": "4"},{"choix": "5"},{"choix": "2"}]},
{"question": "Quelle est le plus grand Campus de Montpellier? ","reponses": [{"choix": "fac des sciences"},{"choix": "fac d'economie"},{"choix": "fac de droit"}]},
{"question": "Quelle est la place la plus vivante à Montpellier?","reponses": [{"choix": "Comedie"},{"choix": "Gare Saint-Roch"},{"choix": "Peyrou"}]}
]
}
Edit: I tried using this code and currently it isn't echoing anything.
<?php
$string = file_get_contents("questionnaire.json");
$json_a = json_decode($string, true);
foreach ($json_a as $question => $reponses) {
echo $reponses['choix'];
}
?>