Codeigniter:如何从数据库获取今天和最近15天之间的数据 [英] Codeigniter: how to get data between today and last 15 days from database
本文介绍了Codeigniter:如何从数据库获取今天和最近15天之间的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库表如下所示
| id | user_name |地址|联系我们|日期|
| ---- | ----------- | --------- | --------- | -------- - |
| 1 | john | NY | 12345 | 2015-4-20 |
| 2 | Mart | NY | 54345 | 2015-4-05 |
| 3 | Drew | US | 67340 | 2015-3-14 |
我的控制器
>
my controller
function is
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);
}
和我的模型
函数是
public function get_data_between_15days($table, $condition)
{
$result = $this->db->get_where($table, $condition);
if($result)
{
return $result->result_array();
}
}
现在我想得到今天和最后的记录15 days from database.and i try like this
now i want to get the records between today and last 15 days from database.and i tried like this
$result = $this->db->query('SELECT * FROM '.$table.' WHERE date BETWEEN DATE_SUB(NOW(), INTERVAL 15 DAY) AND NOW(); AND '.$condition);
但它不工作。我想获得最后15和30天之间的所有记录。我非常感谢您的帮助。谢谢。
but its not working. i want to get all the Records between Last 15 and 30 Days too. I would appreciate for your help. thank you.
推荐答案
使用CodeIgniter标准的查询
Use CodeIgniter standard of query
$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);
这篇关于Codeigniter:如何从数据库获取今天和最近15天之间的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文