diff --git a/BddCorrect/Correcteur.php b/BddCorrect/Correcteur.php index 5459f58..163065d 100644 --- a/BddCorrect/Correcteur.php +++ b/BddCorrect/Correcteur.php @@ -4,19 +4,28 @@ require_once('SqliteDb.php'); +header('Content-type: text/plain'); $db = new SqliteDb(); -$db->exec('DROP TABLE Correct'); -$db->exec('CREATE TABLE Correct (question STRING, reponse STRING)'); -$db->exec("INSERT INTO Correct VALUES ('Ceci est la question 1 ', 'réponse 1')"); - -$reponseUser = $_POST['R1']; -$reponseDb = $db->querySingle('SELECT reponse FROM Correct'); - -if ($reponseDb == $reponseUser) { - echo 'Bonne réponse !'; -} else { - echo 'Mauvaise réponse !'; +$cmpt = 0; +$i = 0; +foreach ($_POST['textbox'] as $textbox) { + $i++; + //$reponseUser = $_POST['']; + $query = $db->prepare('SELECT reponse FROM Correct WHERE rowid= ? '); + $query->bindParam(1, $i); + $result = $query->execute(); + while($row = $result->fetchArray()){ + if ($row['reponse'] == $textbox) { + echo "La réponse à la question n° ".$i." est JUSTE\n"; + $cmpt++; + } + else echo 'La réponse à la question n° '.$i." est FAUSSE\n\n"; + } + + } +echo 'Résultat ' . $cmpt . '/' . $i; + diff --git a/BddCorrect/DAL/QuestionsGateway.php b/BddCorrect/DAL/QuestionsGateway.php new file mode 100644 index 0000000..961aa93 --- /dev/null +++ b/BddCorrect/DAL/QuestionsGateway.php @@ -0,0 +1,23 @@ +db=$db; + } + + public function afficherQuestions() { + $i = 0; + $query = 'SELECT * FROM Correct'; + $query = $this->db->prepare($query); + $result = $query->execute(); + //$resultats = $this->db->query('SELECT found_rows()'); + while($q = $result->fetchArray()){ + $i= $i+1; + $tabQuestions[] = new Question($i,$q['question'],$q['reponse']); + } + return $tabQuestions; + } +} diff --git a/BddCorrect/SqliteDb.php b/BddCorrect/SqliteDb.php index 5eee981..7e83b9b 100644 --- a/BddCorrect/SqliteDb.php +++ b/BddCorrect/SqliteDb.php @@ -2,9 +2,18 @@ class SqliteDb extends SQLite3 { - function __construct() + function __construct() { $this->open('test.db'); + //$this->createTable(); + } + + function createTable(){ + $this->exec('DROP TABLE Correct'); + $this->exec('CREATE TABLE Correct ( question STRING, reponse STRING)'); + $this->exec("INSERT INTO Correct VALUES ('Ceci est la question 1 ', 'r1')"); + $this->exec("INSERT INTO Correct VALUES ('Ceci est la question 2 ', 'r2')"); + $this->exec("INSERT INTO Correct VALUES ('Ceci est la question 3 ', 'r3')"); } } diff --git a/BddCorrect/config/Autoload.php b/BddCorrect/config/Autoload.php new file mode 100644 index 0000000..e338890 --- /dev/null +++ b/BddCorrect/config/Autoload.php @@ -0,0 +1,55 @@ +afficherQuestions(); + } + + function afficherQuestions(){ + global $rep,$vues; + + $model = new Modele(); + $dVueQuestions = $model->afficherQuestions(); + require ($rep.$vues['vuePrincipale']); + + + } +} + diff --git a/BddCorrect/index.php b/BddCorrect/index.php index c4c6003..9dc644b 100644 --- a/BddCorrect/index.php +++ b/BddCorrect/index.php @@ -10,15 +10,13 @@ and open the template in the editor.