mycncart后台列表筛选、分页怎么做

例如:

$row=$this->model_healthdata_health_data->gethealthdata($post);

$data["healthdata"]=$row;

$row是传到view的列表数组

那么要实现分页首先view页添加:

 <div class="row">
          <div class="col-sm-6 text-left"><?php echo $pagination; ?></div>
          <div class="col-sm-6 text-right"><?php echo $results; ?></div>
 </div>

位置自己对照其他模版页查看

接着controller文件中添加:

if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}

$post=array(
"user_id"=>$user_id,
'start'                => ($page - 1) * $this->config->get('config_limit_admin'),
'limit'                => $this->config->get('config_limit_admin')

);

$total = $this->model_healthdata_health_data->getTotal($post);//传递所有筛选条件和分页信息
$pagination = new Pagination();
$pagination->total = $total;//总页数
$pagination->page = $page;//地址栏获取的当前页码
$pagination->limit = $this->config->get('config_limit_admin');每页多少,可以在后台商店设置的选项里面修改
$pagination->url = $this->url->link('healthdata/health_data', 'token=' . $this->session->data['token']. '&page={page}', 'SSL');
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($total - $this->config->get('config_limit_admin'))) ? $total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $total, ceil($total / $this->config->get('config_limit_admin')));

接着model中:

public function getTotal($post){//统计总页数
$where=null;
if($post["user_id"]){
$where .=" and h.user_id=".$post["user_id"];
}//筛选条件加入
$sql = "select count(*) as count from " . DB_PREFIX . "表名 ," . DB_PREFIX . "customer c  where c.customer_id=h.user_id ".$where;
$query = $this->db->query($sql);
$data=$query->row;
return $data['count'];
}

public function gethealthdata($post){//返回列表
$where=null;
if($post["user_id"]){
$where .=" and h.user_id=".$post["user_id"];
}

if (isset($post['start']) || isset($post['limit'])) {
if ($post['start'] < 0) {
$post['start'] = 0;
}

if ($post['limit'] < 1) {
$post['limit'] = 20;
}

$where .= " LIMIT " . (int)$post['start'] . "," . (int)$post['limit'];
}

$sql = "select  * from" . DB_PREFIX . "health_data h," . DB_PREFIX . "customer c  where c.customer_id=h.user_id ".$where;
$query = $this->db->query($sql);
return $query->rows;

}

到此大功告成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值