根据日期检索数据库内容,默认为7天记录

时间:2013-11-07 16:45:34

标签: php codeigniter

我正在尝试显示数据库中的记录,并将其默认为每周记录。 例如,我希望记录默认为2013年11月的Ist - 2013年11月7日(从现在起一周)然后点击上一个链接10月25日 - 10月31日(2013年)和下一个链接11月8日 - 十一月十四日(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);
}

1 个答案:

答案 0 :(得分:0)

您正在寻找基于记录日期的分页方法。

首先,您需要将商店记录的日期作为时间戳整数来避免出现问题,并可以自由更改日期格式并进行计算。

在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查询构建器。

相关问题