RE: Result Shuffling problem in Mysql 04-12-2014, 01:26 PM
#6
Well, I was assuming that you know PDO so that's why I skip where you need to
make a connection. You can add this line at the top of the code to make MySQL
connection with PDO.
Now you can use the object $db.
Now, you did not correctly change the code to your need yet. It should be this way
I wonder if there is ID field in table mcqs?
make a connection. You can add this line at the top of the code to make MySQL
connection with PDO.
Code:
$db = new PDO("mysql:host=localhost;dbname=test", "user", "password");Now you can use the object $db.
Now, you did not correctly change the code to your need yet. It should be this way
Code:
<?php
if (isset($_POST["answer"])) {
// check for correct answer, you need to query
// the question and answer again to compare
$sh = $db->prepare("SELECT * FROM mcqs WHERE id = :id");
$sh->bindValue(":id", $_POST["question_id"]);
$question = $sh->fetch();
} else {
$sh = $db->prepare("SELECT * FROM mcqs WHERE sub LIKE :sub ORDER BY RAND() LIMIT 1");
$sh->bindValue(":sub", "%{$sub}%")
$question = $sh->fetch();
}
?>I wonder if there is ID field in table mcqs?
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)