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 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100