Result Shuffling problem in Mysql 04-11-2014, 07:00 PM
#1
Well I've this script which fetches questions from Mysql database according to the user chosen subject, now the question must appear randomized to the user so that they might not memorize it or guess it but I've tried to implement this feature many times and I've been failing. It seems that this Submit button is causing the problem as when it refreshes the page the question gets changed so as the options and in turn the answer becomes wrong..
I don't understand what else should I do, Immediate help would be appreciated
Code:
//Ex094's Script
$com = "select * from mcqs where subject LIKE '%$sub%' ORDER BY RAND() LIMIT $start, $limit";
$query=mysql_query($com);
while($query2 = mysql_fetch_array($query)) {
echo "Q) " . $query2['question'] . "</br>";
$question = $query2['question'];
$opt1 = $query2['opt1'];
$opt2 = $query2['opt2'];
$opt3 = $query2['opt3'];
$opt4 = $query2['opt4'];
$ans = $query2['ans'];
echo "<form id='formstyle' method='post' action=''>";
echo "<ul id='center'>";
echo "<li><input type='radio' name='answer' value='$opt1' id='choice'>".$query2['opt1']."</input></br></li>";
echo "<li><input type='radio' name='answer' value='$opt2' id='choice'>".$query2['opt2']."</input></br></li>";
echo "<li><input type='radio' name='answer' value='$opt3' id='choice'>".$query2['opt3']."</input></br></li>";
echo "<li><input type='radio' name='answer' value='$opt4' id='choice'>".$query2['opt4']."</input></br></li>";
echo "</ul>";
echo "</br><input id='1' type='submit' value='Submit' name='submit' style='margin-bottom:15px;'></form>";
if(isset($_POST['submit'])) {
$_POST['answer'] == " ";
if($_POST['answer'] == $ans) {
echo "<h3>Correct!</h3>";
} else {
echo "<h3>Wrong</h3>";
echo "The correct answer was <b>$ans</b> </br>";
}
}
}I don't understand what else should I do, Immediate help would be appreciated


![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
![[Image: FvBTsRy.png]](http://i.imgur.com/FvBTsRy.png)