我的数据库表如下所示| id | user_name | address | contact | date | |----|-----------|---------|---------|----------| | 1 | john | NY | 12345 |2015-4-20 | | 2 | Mart | NY | 54345 |2015-4-05 | | 3 | Drew | US | 67340 |2015-3-14 |
我的controller
函数是
function orders()
{
$data['orders'] = $this->common_model->get_data_between_15days('tbl_orders',array('status'=>'1'));
$data['title']='Orders';
$data['main_content']='users/orders_view.php';
$this->load->view('admin/includes/template',$data);
}
我的
model
函数是 public function get_data_between_15days($table, $condition)
{
$result = $this->db->get_where($table, $condition);
if($result)
{
return $result->result_array();
}
}
现在我想从数据库中获取今天和过去15天之间的记录。
$result = $this->db->query('SELECT * FROM '.$table.' WHERE date BETWEEN DATE_SUB(NOW(), INTERVAL 15 DAY) AND NOW(); AND '.$condition);
但它不起作用。我也想获取过去15到30天之间的所有记录。多谢您的协助。谢谢你。
最佳答案
使用CodeIgniter查询标准
$this->db->select('*');
$this->db->where('date BETWEEN DATE_SUB(NOW(), INTERVAL 15 DAY) AND NOW()');
$this->db->where($conditions);
$result = $this->db->get($table);
关于php - Codeigniter:如何从今天开始到最近15天之间从数据库获取数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29740884/