dth42345 2018-01-27 12:14
浏览 116
已采纳

如何使用SELECT和RADIO一起显示数据

I am working on a module where admin can see list of users, i.e. Unapproved, approved and all users in list. I have added a functionality in which a select dropdown is provided and it lists batch numbers from database. Now when admin selects a batch number from drop down and then selects one of the three radios, i.e. Approved, Unapproved and All the list must come based on batch number selected. Till now what I have done is getting the list of users based on radios only. I need to implement this with batch number too so that the admin first selects the batch number from dropdown and then selects the desired radio to see the listings. How can this be implemented? I am posting my code for this and any insight or help will be really helpful.

<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条回答 默认 最新

  • doujiao3072 2018-01-29 11:33
    关注

    It should go like,

    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'";     break;
    
    
    
    }   }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记