为什么在 CodeIgniter 中分页链接对我不起作用? 素材狗 2022-01-01 13:42:52 文章分类:php问题 点击数:次 文章标签 Why are pagination links not working for me in CodeIgniter?(为什么在 CodeIgniter 中分页链接对我不起作用?) 本文介绍了为什么在 CodeIgniter 中分页链接对我不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试为我的产品使用 codeigniter 分页,因此有多个页面哪些产品但对我不起作用,我不知道为什么..这是我的控制器中的分页功能://code om in allecadeaus te bepalen hoeveel producten er per pagina zitten公共功能分页(){//加载分页库$this->load->library('分页');//laad Products_model voor分页$this->load->model('Pagination_model');$this->load->model('Product_model');$config = array();$config["base_url"] = base_url() ."AlleCadeausController/分页";$config["total_rows"] = $this->products->record_count();$config["per_page"] = 24;$config['cur_tag_open'] = '<a><b class="text-success">';$config['cur_tag_close'] = '</b></a>';$config["uri_segment"] = 3;$config['use_page_numbers'] =True;$config['enable_query_strings'];$this->分页->初始化($config);$page = ($this->uri->segment(3)) ?$this->uri->segment(3) : 0;$data['title'] = "产品";$data['products'] = $this->Product_model->selectProducts();$data["links"] = $this->分页->create_links();$this->load->view("allecadeaus", $data);}通过这条线,我从产品表中获取所有产品:$data['products'] = $this->Product_model->selectProducts();我的分页模型:db->count_all("products");}公共函数 fetch_products($limit, $start) {$this->db->limit($limit, $start);$query = $this->db->get_where('users',array('Is_Hidden'=>0));如果 ($query->num_rows() > 0) {foreach ($query->result() as $row) {$data[] = $row;}返回 $data;}返回假;}?>在我的所有产品页面上,我现在尝试回显链接,但它不起作用.我没有看到正确的链接,只有 1 个链接指向其他内容.这是我在所有产品页面上查看的代码:<li><?php echo $links;?></li></nav></div>我做错了什么? 解决方案 请做如下修改:控制器:公共函数分页($row = 0) {//加载分页库$this->load->library('分页');//laad Products_model voor分页$this->load->model('Pagination_model');$this->load->model('Product_model');$config = array();$limit = '24';$config['base_url'] = site_url() .'/AlleCadeausController/分页';$config['full_tag_open'] = "";$config['full_tag_close'] = '';$config['num_tag_open'] = '';$config['num_tag_close'] = '';$config['cur_tag_open'] = '<li class="active"><a href="#">';$config['cur_tag_close'] = '</a></li>';$config['prev_tag_open'] = '';$config['prev_tag_close'] = '</li>';$config['first_tag_open'] = '';$config['first_tag_close'] = '</li>';$config['last_tag_open'] = '';$config['last_tag_close'] = '</li>';$config['prev_link'] = '<i class="fa fa-long-arrow-left"></i>上一页';$config['prev_tag_open'] = '';$config['prev_tag_close'] = '</li>';$config['next_link'] = '下一页<i class="fa fa-long-arrow-right"></i>';$config['next_tag_open'] = '';$config['next_tag_close'] = '</li>';$config["total_rows"] = $this->Product_model->record_count();$config['per_page'] = $limit;$this->分页->初始化($config);$data['links'] = $this->pagination->create_links();$data['products'] = $this->Product_model->selectProducts($row,$limit);$this->load->view("allecadeaus", $data);}型号:function selectProducts($row,$limit){$query = $this->db->get('Your_table_name',$limit,$row);如果 ($query->num_rows() > 0){返回 $query->result_array();}别的 {返回数组();}}函数记录计数(){$this->db->from('Your_table_name');$query = $this->db->get();$row = $query->num_rows();返回 $row;}这会帮助你..谢谢!I'm trying to use codeigniter pagination for my products so there are multiple pages which products but its not working for me and I don't know why.. This is my pagination function in my controller://code om in allecadeaus te bepalen hoeveel producten er per pagina zitten public function pagination() { //load pagination library $this->load->library('pagination'); //laad Products_model voor pagination $this->load->model('Pagination_model'); $this->load->model('Product_model'); $config = array(); $config["base_url"] = base_url() . "AlleCadeausController/pagination"; $config["total_rows"] = $this->products->record_count(); $config["per_page"] = 24; $config['cur_tag_open'] = '<a><b class="text-success">'; $config['cur_tag_close'] = '</b></a>'; $config["uri_segment"] = 3; $config['use_page_numbers'] =True; $config['enable_query_strings']; $this->pagination->initialize($config); $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; $data['title'] = "Products"; $data['products'] = $this->Product_model->selectProducts(); $data["links"] = $this->pagination->create_links(); $this->load->view("allecadeaus", $data); } with this line I'm getting all the products from product table:$data['products'] = $this->Product_model->selectProducts(); My pagination model:<?php class Pagination_model extends CI_Model { public function __construct() { parent::__construct(); } public function record_count() { return $this->db->count_all("products"); } public function fetch_products($limit, $start) { $this->db->limit($limit, $start); $query = $this->db->get_where('users',array('Is_Hidden'=>0)); if ($query->num_rows() > 0) { foreach ($query->result() as $row) { $data[] = $row; } return $data; } return false; } ?> On my all products page I now tried to echo links but it doesn't work. I don't see the correct links and its just 1 link that leads to something else. This is the code in my view on the all products page:<div class="text-center"><nav aria-label="Page navigation"> <ul class="pagination"> <li><?php echo $links; ?></li> </ul> </nav></div> What am I doing wrong? 解决方案 Please make some changes as follows: Controller:public function pagination($row = 0) { //load pagination library $this->load->library('pagination'); //laad Products_model voor pagination $this->load->model('Pagination_model'); $this->load->model('Product_model'); $config = array(); $limit = '24'; $config['base_url'] = site_url() . '/AlleCadeausController/pagination'; $config['full_tag_open'] = "<ul class='pagination'>"; $config['full_tag_close'] = '</ul>'; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['cur_tag_open'] = '<li class="active"><a href="#">'; $config['cur_tag_close'] = '</a></li>'; $config['prev_tag_open'] = '<li>'; $config['prev_tag_close'] = '</li>'; $config['first_tag_open'] = '<li>'; $config['first_tag_close'] = '</li>'; $config['last_tag_open'] = '<li>'; $config['last_tag_close'] = '</li>'; $config['prev_link'] = '<i class="fa fa-long-arrow-left"></i>Previous Page'; $config['prev_tag_open'] = '<li>'; $config['prev_tag_close'] = '</li>'; $config['next_link'] = 'Next Page<i class="fa fa-long-arrow-right"></i>'; $config['next_tag_open'] = '<li>'; $config['next_tag_close'] = '</li>'; $config["total_rows"] = $this->Product_model->record_count(); $config['per_page'] = $limit; $this->pagination->initialize($config); $data['links'] = $this->pagination->create_links(); $data['products'] = $this->Product_model->selectProducts($row,$limit); $this->load->view("allecadeaus", $data); } Model:function selectProducts($row,$limit) { $query = $this->db->get('Your_table_name',$limit,$row); if ($query->num_rows() > 0){ return $query->result_array(); } else { return array(); } } function record_count(){ $this->db->from('Your_table_name'); $query = $this->db->get(); $row = $query->num_rows(); return $row; } This will help you..thanks! 这篇关于为什么在 CodeIgniter 中分页链接对我不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网! 上一篇:PHP 搜索结果的分页 下一篇:分页不断显示 SQL 数据的相同部分 相关文章 dedecms织梦有缩略图则显示无缩略图不显示很多时候用dedecms织梦建站的时候会遇到在调用缩略图,要怎么做到有缩略图的时候才显示,无缩略图就不显示,方法如下 [field:array runphp='yes']@me = (strpos(@me['litpic'],'defaultpic') ? "":""); [/field:array] 带内容简介示例代码如下: [field:array runphp=’yes’ AndroidStudio图片压缩工具ImgCompressPlugin使用实例AndroidStudio图片压缩工具ImgCompressPlugin使用实例 目录 正文 如何使用 配置信息 如何选择合适的压缩方式 最佳实践 问题解答 正文 项目中集成了TinyPng,500张免费 几个key轮流使用 非常方便However,最近发现总是报错 Caused by: javax.net.ssl.SSLHandshakeException: PHP检查空值的方法总结PHP检查空值的方法总结 1.使用empty(),检测变量是否为空 ?php $a = 'test'; $b = array('key1' = 'value1'); $class = new stdClass(); var_dump(empty($c)); // 输出 bool(true) var_dump(empty($b['key2'])); // 输出 bool(true) var_dump(empty($class)); // 输出 bool(false) var_dump(empty($clas PHP如何删除关联数组中键值PHP如何删除关联数组中键值 1.使用unset()函数可以用于取消设置关联数组中的键及其值. // 声明关联数组 $arr = array( 1 = 加, 2 = 减, 3 = 乘, 4 = 除 ); // 关联数组中删除键1及其值 unset($arr['1']); // 显示数组元素 var_dum ... PHP获取文件属性的最简单方法PHP获取文件属性的最简单方法 1.filesize($filename) 返回指定文件大小. 如果成功,会返回文件大小的字节数:如果失败,则返回 FALSE. ?php header(content-type:text/html;charset=utf-8); $filename = test.txt; echo {$filename} 文件的大小为:.filesize($filename); ? 2.filetype($filename .. PHP中多字节字符串操作实例详解PHP中多字节字符串操作实例详解 目录 前言 字符串操作 字符串正则操作 字符串编码转换 HTTP 参数操作 其它属性查看 总结 前言 什么是多字节的字符串操作呢?其实不少的同学可能都已经使用过了,但我们还是要从最基础的问题说起. 一个字符占几个