php - Retrieve data from mysql through checkbox -


i want search question mysql using combobox. if select chapter number 1 in combobox, want display question chapter 1 have.

in suppose chapter 1 contains 2 questions, chapter 2 contains questions , on. when select chapter number 1 doesn't display question chapter 1 have. print last question last chapter. how can solve problem?

 <?php              $sql= "select distinct chapter 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 math 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); // gives last question.       echo $question;                  }    ?> 

your mistake selecting questions last iteration of query select chapters.

... while($info=mysql_fetch_array($q)){   $d1 = $info['chapter'];          echo "<option> ".$info['chapter']."</option>";           } echo "</select>";          $sql1 = "select question math chapter=$d1";  ... 

will select last chapter. have problem. assuming want show questions when user select value dropdown, have send selection using post/get/ajax php , generate results based on selection. this:

    if(!isset($_post['fname']))     {        $sql= "select distinct chapter math";                $q= mysql_query($sql);                echo "<select name='fname'>";           while($info=mysql_fetch_array($q)){               echo "<option> ".$info['chapter']."</option>";                  }        echo "</select>";           }        else     {       $sql1 = "select question math chapter = " . $_post['fname'];               $sql1_res = mysql_query($sql1) or die(mysql_error());            while($row = mysql_fetch_array($sql1_res)){           $question=htmlspecialchars_decode($row['question'], ent_quotes); // gives last question.         echo $question;                  }      } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -