简体   繁体   中英

How to get data by date from database to using codeigniter

I want to get data of last week. I try many ways but always get errors or nun results.

$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();

Your query operator to check greater and lesser is wrong. You need to check the below:

`date_row` <= '2014/12/08' AND `postdate` >= '2014/12/01'
$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';
}

Try with the following code. It will solve your problem.

$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 variable have stored the last week data. Use the following code for print the data.

print '<pre>';
print_r($result);
$query =   SELECT * FROM "tablename" 
           WHERE "date" >= '2014-12-30' AND "date" <= '2014-12-01'
$q = $this->db->query($query);
$rr = $q->result();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM