dsgd4654674 2018-10-12 06:27 采纳率: 0%
浏览 37

如何在无线电选择按钮上执行不同的查询?

I am trying to fetch the different result on different selection of radio buttons.I have three buttons in my code. I want when user select all the fields like select tsm, select sr, from, to and any of radio selection execute different queries. I want when user select first radio then execute one query if user select second radio then execute different query and so on. But when I am trying this my result is not coming means my data is not passing to query so that it can fetch the result.

<select class="form-control" name="tsm_id" id="tsm_id">
    <option value=""><b>SELECT TSM</b></option>
    <?php echo fill_year($connect); ?> 
</select>
<br><br>

<select class="form-control" name="sr_id" id="sr_id">
  <option value="" selected>SELECT SR</option>   
</select>
<br><br><br><br>
<div class="row">
     <div class="input-daterange">
      <div class="col-md-4">
       <label>From:</label><input type="text" name="start_date" id="start_date" data-provide="datepicker" class="form-control" />
     </div>
     <div class="col-md-4">
       <label>To:</label><input type="text" name="end_date" id="end_date" data-provide="datepicker" class="form-control" />
     </div>      
   </div>
   <div><br><br><br><br>
<label>Visited during this period:</label><input type="radio" name="options" value="first" id="first" class="options">
<label>Not Visited during this period:</label><input type="radio" name="options" value="second" id="second" class="options">
<label>Never Visited:</label><input type="radio" name="options" value="third" id="third" class="options"><br>
    <input type="button" name="search" id="search" value="Search" class="btn btn-info" />
  </div>
</div><br><br><br>

<script type="text/javascript">
  $(document).ready(function(){  
   $('#sr_id').change(function(){  
    $('.options').click(function(){
     var sr_id = $('#sr_id').val();  
     var start_date = $('#start_date').val();
     var end_date = $('#end_date').val();
    var first=$(this).val();
     $.ajax({  
      url:"http://localhost/sales/fetch_retailer.php",  
      method:"GET",
      data:{sr_id:sr_id,start_date:start_date,end_date:end_date},  
      dataType:"json",                  
      success:function(data){ 
        alert("success")
        var test=JSON.stringify(data);
        console.log(test)
        $('#count_data').html('');
        for (var i in data)
        {
          $("#count_data").append("<tr></td><td class='text-center'>"+data[i].retailer_shop_name+"</td><td class='text-center'>"+data[i].last_visit+"</td></tr>");
        }
      }
    });
   }); 
  });
 });
</script>

if(isset($_GET['options']) && !empty($_GET['options'])){
    if($_GET['options'] == 'first'){
   $sql=sprintf("SELECT 
   tbl_retailer.retailer_shop_name,
   tbl_retailer.retailer_id,
   max(tbl_visit_master.visit_DateTime) as last_visit
   from tbl_retailer
   left join tbl_member on tbl_member.employee_id=tbl_retailer.sr_id
   left join tbl_visit_master on tbl_retailer.retailer_id=tbl_visit_master.retailer_id where tbl_retailer.sr_id='".$_GET["sr_id"]."' and tbl_retailer.isgroup=1 
   group by retailer_id having (max(tbl_visit_master.visit_DateTime)) BETWEEN '".$_GET["start_date"]."' AND '".$_GET["end_date"]."'");
  }  
</div>
  • 写回答

2条回答 默认 最新

  • douche5961 2018-10-12 06:55
    关注

    you are trying to get the data of options in php code like this $_GET['options'] but you are not passing it in data attribute of ajax

    data:{sr_id:sr_id,start_date:start_date,end_date:end_date}

    try it with this

    data:{sr_id:sr_id, start_date:start_date, end_date:end_date, options:first}

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据