我试图在不同的单选按钮上获取不同的结果。我的代码中有三个按钮。我想当用户选择所有字段,如选择tsm,选择sr,from,to和任何无线电选择执行不同的查询。我想当用户选择第一个无线电然后执行一个查询,如果用户选择第二个无线电然后执行不同的查询,以此类推。但是当我尝试这样做时,我的结果不来意味着我的数据没有传递给查询以便它可以获取结果。
<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"]."'");
}
2条答案
按热度按时间67up9zun1#
请用以下代码替换您的ajax调用,然后再试一次。
f3temu5u2#
您正试图在php代码中获得如下选项的数据
$_GET['options']
但您不能将它传递到ajax的数据属性中data:{sr_id:sr_id,start_date:start_date,end_date:end_date}
试试这个data:{sr_id:sr_id, start_date:start_date, end_date:end_date, options:first}