我想获得上周的数据。我尝试了很多方法,但总是得到错误或修女结果。
$query = "SELECT `toy1`,`toy2`
FROM
`tabel`
WHERE `data1` != 'str' &&`data2` = 'str' && `date_row` >= '2014/12/08' AND `postdate` <= '2014/12/01' Limit 0,6";
$q = $this->db->query($query);
$rr = $q->result();
答案 0 :(得分:0)
您的查询运算符检查更大和更小是错误的。你需要检查以下内容:
`date_row` <= '2014/12/08' AND `postdate` >= '2014/12/01'
答案 1 :(得分:0)
$this->db->select('toy1,toy2');
$this->db->from('tabel');
$this->db->where('data1 !=','str');
$this->db->where('data2 !=','str');
$this->db->where('date_row >= ', date('Y/m/d', strtotime('-1 week')));
$this->db->where('postdate >= ', date('Y/m/d', strtotime('-1 week')));
$this->db->limit(7);
$query = $this->db->get();
if($query->num_rows > 0)
{
$result = $query->result_array();
// get your array
}
else
{
echo 'no result';
}
答案 2 :(得分:0)
尝试使用以下代码。它会解决你的问题。
$this->db->select('toy1,toy2');
$this->db->from('tabel');
$this->db->order_by('postdate','desc');
$this->db->limit(7);
$query = $this->db->get();
$result = $query->result_array();
$ result变量已经存储了上周的数据。使用以下代码打印数据。
print '<pre>';
print_r($result);
答案 3 :(得分:-1)
$query = SELECT * FROM "tablename"
WHERE "date" >= '2014-12-30' AND "date" <= '2014-12-01'
$q = $this->db->query($query);
$rr = $q->result();