I want to search question from mysql using ComboBox. If I select chapter number one in ComboBox, I want to display that question which only chapter one have.
In this suppose my chapter 1 contains 2 questions, chapter 2 contains some questions and so on. When I select chapter number 1 then it doesn't display question that chapter 1 have. It will only print the last question from the last chapter. How can I solve this problem?
<?php
$sql= "select distinct chapter from math";
$q= mysql_query($sql);
echo "<select name='fname'>";
while($info=mysql_fetch_array($q)){
$d1 = $info['chapter'];
echo "<option> ".$info['chapter']."</option>";
}
echo "</select>";
$sql1 = "select question from math where chapter=$d1";
$sql1_res = mysql_query($sql1) or die(mysql_error());
while($row = mysql_fetch_array($sql1_res)){
$question=htmlspecialchars_decode($row['question'], ENT_QUOTES); // It gives only last question.
echo $question;
}
?>