使用下拉列表和radiobutton列出数据

时间:2018-01-29 09:22:01

标签: php mysql drop-down-menu radio-button

我正在开发一个模块,管理员可以在其中查看用户列表,即未批准,已批准以及列表中的所有用户。我添加了一个功能,其中提供了一个选择下拉列表,它列出了数据库中的批号。现在,当管理员从下拉列表中选择一个批次编号,然后选择三个无线电中的一个,即已批准,未批准和所有列表必须基于所选的批次编号。到目前为止,我所做的只是获取基于无线电的用户列表。我还需要使用批号来实现它,以便管理员首先从下拉列表中选择批号,然后选择所需的无线电以查看列表。如何实施?我发布了我的代码,任何见解或帮助都会非常有用。

<form  action=""  method="POST">
  <div class="col-md-6">
    <div class="col-md-4">
      <label for="username" class="control-label">Batch No. :
      </label>
    </div>
    <div class="col-md-8">
      <select name="batchnumber" class="form-control" required id="batchno" >   
        <option value="">select batch number
        </option>                 
        <?php 
$sql = mysql_query("SELECT DISTINCT rpp_regn_bulkbatch_no,rpp_id FROM tbl_regn_prescribed_parameters where rpp_regn_bulkbatch_no  != 0");
while ($row = mysql_fetch_assoc($sql)){   
echo "<option value=" . $row['id'] . ">" . $row['rpp_regn_bulkbatch_no'] . "</option>";
}
?>
      </select>
    </div>
  </div>    
  <input type='radio'  name='users' value='unapproved' checked /> Unapproved Candidates &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input type='radio'  name='users' value='approved' /> Approved Candidates &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input type='radio' id='show' name='users' value='all'  /> All Candidates 
  <input type="submit" value="View Candidates" id="submit" class="btn btn-success">
And for PHP,
if((isset($_POST['users'])) && (isset($_POST['batchnumber'])) ){


    $users=$_POST['users'];
    $batchnumber= $_POST['batchnumber'];

}else{
    $users='';
    $batchnumber='';
}


switch ($users)

{

case "all":
  $sqlQuery = "SELECT * FROM tbl_user WHERE type =3  ";         
break;

case "approved":
  $sqlQuery = "SELECT * FROM tbl_user WHERE type =3 AND status =1";    break;

case "unapproved":
  $sqlQuery = "SELECT * FROM tbl_user WHERE type =3 AND status =0";    
 break;

} 

1 个答案:

答案 0 :(得分:0)

它应该是,

if (isset($_POST['submit1'])) {


 if(isset($_POST['batchnumber'])) {

$selected = $_POST['batchnumber'];

}else { echo "empty.";$selected='';}

if(isset($_POST['users'])){


    $users=$_POST['users']; 
}else{
    $users='';
}


switch ($users)

{

case "all":
  $sqlQuery = "SELECT * FROM tbl_user WHERE type =3 AND bulk_batch_number= '$selected' ";          
break;

case "approved":
  $sqlQuery = "SELECT * FROM tbl_user WHERE type =3 AND status =1 
break;

case "unapproved":
  $sqlQuery = "SELECT * FROM tbl_user WHERE type =3 AND status =0 AND bulk_batch_number= '$selected'