Login Register


Result Shuffling problem in Mysql filter_list
Author
Message
RE: Result Shuffling problem in Mysql #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.

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?






Messages In This Thread
Result Shuffling problem in Mysql - by Ex094 - 04-11-2014, 07:00 PM



Users browsing this thread: