我正在尝试显示数据库中的记录并将其默认为每周记录。例如,我想让记录默认为 2013 年 11 月 - 2013 年 11 月 7 日的 Ist(即一周后),然后单击上一个链接 2013 年 10 月 25 日至 10 月 31 日(2013 年)和下一个链接 11 月 8 日至 11 月 14 日 (2013)
我正在使用php和CodeIgniter。任何可以帮助我的帮助或页面链接将不胜感激。
我现在要做的就是显示所有记录并使用分页每页显示 7 个字段,但我需要每周显示,默认为周五至周四的当前周。
public function index()
{
//Count all records
$shopID= $this->uri->segment(2);
session_id($shopID);
$this->db->where('BDP_COST_CENTRE_NUMBER', $shopID);
$count = $this->db->count_all_results('WHOUSE1.DLY_BWR_DLY_PERFORMANCE');
//Set up pagination
$perpage = 7;
if ($count > $perpage)
{
$config['base_url'] = 'http://bwr/index.php/daily_shop_performance/' . $shopID . '/';
$config['total_rows'] = $count;
$config['per_page'] = $perpage;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$this->data['pagination']=$this->pagination->create_links();
$offset = $this->uri->segment(3);
} else {
$this->data['pagination']='';
$offset = 0;
}
$shopID= $this->uri->segment(2);
$this->db->where('BDP_COST_CENTRE_NUMBER', $shopID);
$this->db->limit($perpage, $offset);
**$this->data['shops_performances'] = $this->performance_m->get();**
$this->data['subview'] = 'page/performance_page';
$this->load->view('_layout_main', $this->data);
}
您正在寻找基于记录日期的分页方法。
首先,您需要将记录的日期存储为时间戳整数以避免出现问题,并可以自由更改日期格式并进行计算。
在 where 子句上,您需要这样的东西(如果您间隔 7 天):
public function getRecords($start, $interval = 7)
{
$limit = (24 * 60 *60) * $interval;
$sql = "SELECT * FROM my_table WHERE record_date > $start AND record_date < interval";
}
我需要查看您的代码,以获取更具体的帮助...我的代码是通用示例,请改用 CodeIgniter 查询生成器。