douxuexiao1748 2018-12-03 06:08
浏览 62
已采纳

如何根据fromdate和todate过滤数据?

This is my construct query, i need to filter data based on fromdate and todate,and also based on adminid, whats wrong am i doing here,is there any other way?

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;
}
  • 写回答

2条回答 默认 最新

  • douzhan1935 2018-12-03 06:22
    关注

    You're not concatenating. You forgot the '.'. There is also no need to append the 'NULL'. If you don't want to do anything with executive_id, then don't add anything to the constructed query.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败