如何根据 fromdate 和 todate 过滤数据?
how to filter data based on fromdate and todate?
这是我的构造查询,我需要根据fromdate和todate过滤数据,还要根据adminid过滤数据,我在这里做错了什么,还有其他方法吗?
function constructFilterQueryrelogin($paymentStatusCode, $appCode,$adminId,$fromDateId,$toDateId){
$query = "";
// From To Date Query for Updation Date
$currentDateTime = date('Y-m-d H:i:s', time());
$fromDateId = date('Y-m-d H:i:s', strtotime('0 days', strtotime($fromDateId)));
$toDateId = date('Y-m-d H:i:s', strtotime('+ 1 days', strtotime($toDateId)));
if(($_POST['fromDateId'] && $_POST['toDateId']) != ''){
$query = "Login_Date >= '".$fromDateId."' AND Login_Date <= '".$toDateId."' ";
}
else{
$query = "Login_Date <= '".$currentDateTime."' ";
}
//get data based on executive_Id
if($_POST['adminId'] != ''){
$query = " Executive_Id = '".$_POST['adminId']."' ";
}
else{
$query = "Null";
}
//Apps Filter Query
if($_POST['appCode'] != ""){
switch($_POST['appCode']){
case 1: $query .= " AND App_Id LIKE '%".$_POST['appCode']."%' "; break;
default: $query .= " AND App_Id LIKE '%".$_POST['appCode']."%' ";
}
}
// $filterApps = ($_GET['appCode'] != "") ? ' Where `App_Id` = '.$_GET['appCode'].' ' : "";
//Payment Status Query
$currentDateTime = date('Y-m-d H:i:s', time());
$expiringTimeLimit = date('Y-m-d H:i:s', strtotime('+ 30 days', strtotime($currentDateTime)));
switch($paymentStatusCode){
case 1: $query .= " AND Max_Sub_End_Timestamp IS NULL "; break;
case 2: $query .= " AND Max_Sub_End_Timestamp <= '".$currentDateTime."' "; break;
case 3:
$query .= " AND Max_Sub_End_Timestamp > '".$currentDateTime."' AND Max_Sub_End_Timestamp <= '".$expiringTimeLimit."' "; break;
case 4: $query .= " AND Max_Sub_End_Timestamp > '".$expiringTimeLimit."' "; break;
default: $query .= "";
}
return $query;
}
你没有串联。你忘记了'.'。也不需要附加 'NULL'。如果您不想对 executive_id 执行任何操作,则不要向构造的查询中添加任何内容。
需要完成 2 个步骤才能做到这一点。
- 在 if(($_POST['fromDateId'] && $_POST['toDateId']) != '') 语句中的“Login_date”之前添加 space
- 删除“NULL”
祝你好运
这是我的构造查询,我需要根据fromdate和todate过滤数据,还要根据adminid过滤数据,我在这里做错了什么,还有其他方法吗?
function constructFilterQueryrelogin($paymentStatusCode, $appCode,$adminId,$fromDateId,$toDateId){
$query = "";
// From To Date Query for Updation Date
$currentDateTime = date('Y-m-d H:i:s', time());
$fromDateId = date('Y-m-d H:i:s', strtotime('0 days', strtotime($fromDateId)));
$toDateId = date('Y-m-d H:i:s', strtotime('+ 1 days', strtotime($toDateId)));
if(($_POST['fromDateId'] && $_POST['toDateId']) != ''){
$query = "Login_Date >= '".$fromDateId."' AND Login_Date <= '".$toDateId."' ";
}
else{
$query = "Login_Date <= '".$currentDateTime."' ";
}
//get data based on executive_Id
if($_POST['adminId'] != ''){
$query = " Executive_Id = '".$_POST['adminId']."' ";
}
else{
$query = "Null";
}
//Apps Filter Query
if($_POST['appCode'] != ""){
switch($_POST['appCode']){
case 1: $query .= " AND App_Id LIKE '%".$_POST['appCode']."%' "; break;
default: $query .= " AND App_Id LIKE '%".$_POST['appCode']."%' ";
}
}
// $filterApps = ($_GET['appCode'] != "") ? ' Where `App_Id` = '.$_GET['appCode'].' ' : "";
//Payment Status Query
$currentDateTime = date('Y-m-d H:i:s', time());
$expiringTimeLimit = date('Y-m-d H:i:s', strtotime('+ 30 days', strtotime($currentDateTime)));
switch($paymentStatusCode){
case 1: $query .= " AND Max_Sub_End_Timestamp IS NULL "; break;
case 2: $query .= " AND Max_Sub_End_Timestamp <= '".$currentDateTime."' "; break;
case 3:
$query .= " AND Max_Sub_End_Timestamp > '".$currentDateTime."' AND Max_Sub_End_Timestamp <= '".$expiringTimeLimit."' "; break;
case 4: $query .= " AND Max_Sub_End_Timestamp > '".$expiringTimeLimit."' "; break;
default: $query .= "";
}
return $query;
}
你没有串联。你忘记了'.'。也不需要附加 'NULL'。如果您不想对 executive_id 执行任何操作,则不要向构造的查询中添加任何内容。
需要完成 2 个步骤才能做到这一点。
- 在 if(($_POST['fromDateId'] && $_POST['toDateId']) != '') 语句中的“Login_date”之前添加 space
- 删除“NULL”
祝你好运