您好我正在处理的项目有一个过滤选项供管理员根据日期对数据进行排序,我将根据选择值显示数据这里是代码
<select id="duration" class="main-admin selectpicker">
<option value="today">Today</option>
<option value="3d">3 Days Ago</option>
<option value="1w">1 Week/7 Days Ago</option>
<option value="3w">3 Weeks Ago</option>
<option value="1m">1 Month Ago</option>
<option value="all">Show All 1 Month And Older</option>
</select>
这是管理员选择不同日期
的选择框$('#duration').on('change', function() {
$("#appendclientdata").html("");
if(this.value=="3d"){
value=3;
}
else if(this.value=="1w"){
value=7;
}
else if(this.value=="3w"){
value=21;
}
else if(this.value=="1m"){
value=30;
}
if(this.value=="today"){
//geting current date in javascript
var dt = new Date();
var date=(dt.getMonth() + 1)+ "/" + dt.getDate() + "/" + dt.getFullYear();
//geting current date in javascript
$.ajax({
type: 'post',
url: 'duration_client_data_get.php',
dataType: 'json',
data:'date='+date,
success: function (data) {
for(i=0;i<data.length;i++){
var append='<div class="panel panel-default"><div class="panel-heading"><span class="admin-white-box">CLIENT ID:</span><span class="admin-white-box"> '+data[i].client_id+'</span><span style="float: right;" class="admin-white-box">'+data[i].time+'</span></div><div class="panel-body"> <div class="col-lg-2"><span class="classfloat client-information-default"><p>Full Name:</p><p>Email:</p><p>Phone:</p><p>City:</p></span></div><div class="col-lg-1"><span class="client-information-detail"><p>'+data[i].fullname+'</p><p>'+data[i].email+'</p><p>'+data[i].phone+'</p><p>'+data[i].city+'</p></span></div> <div class="col-lg-9"> <button onclick=window.location.href="admin_leadbox2.php?id='+data[i].client_id+'" class="admin_view_more_details_button">VIEW MORE DETAILS</button></div> <div class="col-lg-9"> <button href="#" class="admin_request_quote">SETTINGS</button></div></div>';
$("#appendclientdata").append(append);
}
}
});
}
else
{
var dt = new Date();
var today=(dt.getMonth() + 1)+ "/" + dt.getDate() + "/" + dt.getFullYear();
dt.setDate(dt.getDate() - value);
var daysback=(dt.getMonth() + 1)+ "/" + dt.getDate() + "/" + dt.getFullYear();
var obj={currentdate:today,daysback:daysback};
$.ajax({
type: 'post',
url: 'duration_client_data_get.php',
dataType: 'json',
data:obj,
success: function (data) {
for(i=0;i<data.length;i++){
var append='<div class="panel panel-default"><div class="panel-heading"><span class="admin-white-box">CLIENT ID:</span><span class="admin-white-box"> '+data[i].client_id+'</span><span style="float: right;" class="admin-white-box">'+data[i].time+'</span></div><div class="panel-body"> <div class="col-lg-2"><span class="classfloat client-information-default"><p>Full Name:</p><p>Email:</p><p>Phone:</p><p>City:</p></span></div><div class="col-lg-1"><span class="client-information-detail"><p>'+data[i].fullname+'</p><p>'+data[i].email+'</p><p>'+data[i].phone+'</p><p>'+data[i].city+'</p></span></div> <div class="col-lg-9"> <button onclick=window.location.href="admin_leadbox2.php?id='+data[i].client_id+'" class="admin_view_more_details_button">VIEW MORE DETAILS</button></div> <div class="col-lg-9"> <button href="#" class="admin_request_quote">SETTINGS</button></div></div>';
$("#appendclientdata").append(append);
}
}
});
}
});
这是发送到服务器的ajax请求
<?php
include("db.php");
if(isset($_POST['date'])){
$date = $_POST['date'];
//echo "inside date.<br>";
$i=0;
$query=mysqli_query($db,"SELECT * FROM `atom_users` WHERE dateforlogic='$date'");
while($row=mysqli_fetch_array($query))
{
$data2[$i]['client_id']=$row['client_id'];
$data2[$i]['fullname']=$row['fullname'];
$data2[$i]['email']=$row['email'];
$data2[$i]['phone']=$row['phone'];
$data2[$i]['city']=$row['city'];
$data2[$i]['time']=$row['time'];
$i++;
}
}
if (isset($_POST['currentdate'])){
//echo "inside other.<br>";
$contractDateEnd= $_POST['currentdate'];
$contractDateBegin=$_POST['daysback'];
//echo "date begin request"."<br>".$contractDateBegin."<br>";
//echo "date end request"."<br>".$contractDateEnd."<br>";
//
$i=0;
$query=mysqli_query($db,"SELECT * FROM `atom_users`");
while($row=mysqli_fetch_array($query))
{
// echo "server date".$row['dateforlogic']."<br>";
// echo $row['dateforlogic'].">" . $contractDateBegin."&&". $row['dateforlogic'] ."<". $contractDateEnd."<br>";
if (($row['dateforlogic'] > $contractDateBegin) && ($row['dateforlogic'] < $contractDateEnd))
{
// echo "inside true"."<br>";
$data2[$i]['client_id']=$row['client_id'];
$data2[$i]['fullname']=$row['fullname'];
$data2[$i]['email']=$row['email'];
$data2[$i]['phone']=$row['phone'];
$data2[$i]['city']=$row['city'];
$data2[$i]['time']=$row['time'];
$i++;
}
}
}
echo json_encode($data2);
exit();
?>
这是处理请求的php代码
这段代码适用于每个场景并返回所需数据,但问题是当管理员选择1周/ 7天前选项此代码不起作用时错误是
Notice: Undefined variable: data2 in C:\xampp\htdocs\atom\duration_client_data_get.php on line 60
null
这个问题只出现在1周/ 7天前的情况下,选项我做了一个干运行,从逻辑上说它工作正常,条件满足每个场景,但在1周的情况下不是条件成立/ 7天前,我根本无法理解为什么只给出一个选项的问题并且其余的工作正常?