-2

如何在此处获取最近两天的记录是我的查询,但出现错误。

function getbdologHistoryByRefManuals($obj)
{
    $this->db->select('bdo_logs.*,transaction_statuses.status');
    $this->db->from('bdo_logs');
    $this->db->join('transactions','transactions.id=bdo_logs.id');
    $this->db->join('transaction_statuses','transaction_statuses.id=transactions.trans_status_id');
    $this->db->where('log_date >', ADDDATE( CURDATE( ) , INTERVAL -2 DAY ));

    $query = $this->db->get();

    //echo $this->db->last_query();
    if($query->num_rows() == 0){
        return null;
    }

            return $query->result();
}
4

2 回答 2

2
function getbdologHistoryByRefManuals($obj)
{
    $this->db->select('bdo_logs.*,transaction_statuses.status');
    $this->db->from('bdo_logs');
    $this->db->join('transactions','transactions.id=bdo_logs.id');
    $this->db->join('transaction_statuses','transaction_statuses.id=transactions.trans_status_id');
    $this->db->where('DATE(log_date) >', 'ADDDATE( CURDATE( ) , INTERVAL -2 DAY )');

    $query = $this->db->get();

    if($query->num_rows() == 0){
        return null;
    }

    return $query->result();
}

您缺少在 where 子句中包装 ADDDATE 函数

编辑:
或者你可以这样称呼它

$query  ="  SELECT
                bdo_logs.*,
                transaction_statuses.status
            FROM bdo_logs
            JOIN transactions 
                ON transactions.id  =   bdo_logs.id
            JOIN transaction_statuses 
                ON transaction_statuses.id  =   transactions.trans_status_id
            WHERE DATE(log_date) > ADDDATE( CURDATE( ) , INTERVAL -2 DAY )";
$result = $this->db->query($query); 
于 2013-04-25T07:07:45.933 回答
2

简单的方法:

$today = date('Y-m-d');
$newdate = date('Y-m-d', strtotime("-2 days"));
echo $today;
echo '<br />';
echo $newdate;

现在,放入$newdatewhere 条件。

于 2013-04-25T08:22:50.440 回答