Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter 用于显示数据库中特定数据的代码点火器分页?_Codeigniter - Fatal编程技术网

Codeigniter 用于显示数据库中特定数据的代码点火器分页?

Codeigniter 用于显示数据库中特定数据的代码点火器分页?,codeigniter,Codeigniter,我想通过使用CI分页来显示数据库中的一些特定数据。但函数中的默认分页passess参数给我带来了问题 这是我的控制器 function page($catagoryid){ $this->load->library('pagination'); $config['base_url'] = base_url().'index.php/pagination/page/'; $count = $this->db->query("select * from tbl_pr

我想通过使用CI分页来显示数据库中的一些特定数据。但函数中的默认分页passess参数给我带来了问题

这是我的控制器

function page($catagoryid){

 $this->load->library('pagination');
 $config['base_url'] = base_url().'index.php/pagination/page/'; 

$count = $this->db->query("select * from tbl_products where category_id='$categoryid'");
 $total=$count->num_rows();

 $per_page = 4;
 $config['total_rows'] = $total;
 $config['per_page'] = $per_page;
 $this->pagination->initialize($config);
 $data['pagination'] = $this->pagination->create_links();
 $this->load->model("mpagination");
 $data['list'] = $this->mpagination->get_s(,$categoryid,$config['per_page'],$this->uri->segment(3));
 if ($data['list']!== null){

 $this->load->view('pagination_view', $data);
 }
else {
$this->load->view('noresult');

} 
 }
这是我的模型

function get_s($categoryid,$num, $offset) {


$this->db->select ('*');
        ->where('category_id',$categoryid);  // field name

$sql = $this->db->get('tbl_products',$num, $offset); // table name
if ($sql->num_rows () >0) {

    return $sql->result();
 }
 else {
 return null;
}
}
这是我的看法

 <?php
 foreach($list as $row):?>




    <?php echo $row->_prduct_id."   ".$row->name."   ".$row->description;?>
    <br/>



  <?php endforeach;?>
  <br/>
     <?php echo $pagination; ?>



这段代码一开始可以工作,但当我单击分页的第二个链接时,它将不工作,因为默认情况下,分页将其值作为参数发送到url,并且不显示数据。
我能做什么?

我没有正确理解您的代码,但这是您需要的分页方式

public function page($category_id)
{
    $result = $this->model_file->model_function($category_id);

    $start_index = 0;

    $total_rows = count($result);

    $items_per_page = 10;

    $filtered = array_splice($result,$start_index,$items_per_page);

    $model['data'] = $filtered;

    $model['page_link'] = create_page_links (base_url()."/controller_file_name/page", $items_per_page, $total_rows);

    $this->load->view('view_file_name_path',$model);

    }

    function create_page_links($base_url, $per_page, $total_rows) {

    $CI = & get_instance();
    $CI->load->library('pagination');

    $config['base_url'] = $base_url;
    $config['total_rows'] = $total_rows;
    $config['per_page'] = $per_page; 

    $CI->pagination->initialize($config); 

    return $CI->pagination->create_links();

    }
像这样试试

public function index($offset = 0) 
{
    $language_id = 1;
    $this->load->library('pagination');
    $limit = 10;

    $total = $this->legend_model->get_legend_count($language_id);

    $config['base_url'] = base_url().'legend/index/';
    $config['total_rows'] = $total;
    $config['per_page'] = $limit;
    $config['uri_segment'] = 3;

    $config['first_link'] = '<< First';
    $config['last_link'] = 'Last >>';
    $config['next_link'] = 'Next ' . '&gt;';
    $config['prev_link'] = '&lt;' . ' Previous';
    $config['num_tag_open'] = '<span class="number">';
    $config['num_tag_close'] = '</span>';

    $config['cur_tag_open'] = '<span class="current"><a href="#">';
    $config['cur_tag_close'] = '</a></span>';

    $this->pagination->initialize($config);
    $data['offset'] = $offset;
    $data['legends'] = $this->legend_model->get_legend($language_id, $limit, $offset);

    $this->template->write('title', 'Legend : Manage Legend');
    $this->template->write_view('content', 'legend/index', $data);
    $this->template->render();
}
公共功能索引($offset=0)
{
$language_id=1;
$this->load->library('pagination');
$limit=10;
$total=$this->legend\u model->get\u legend\u count($language\u id);
$config['base_url']=base_url().'legend/index/';
$config['total_rows']=$total;
$config['per_page']=$limit;
$config['uri_段]]=3;
$config['first_link']='>';
$config['next_link']=“next.”;
$config['prev_link']=''Previous';
$config['num\u tag\u open']='';
$config['num\u tag\u close']='';
$config['cur_tag_open']='';
$this->pagination->initialize($config);
$data['offset']=$offset;
$data['legends']=$this->legend\u model->get\u legend($language\u id,$limit,$offset);
$this->template->write('title','Legend:managelegend');
$this->template->write_view('content','legend/index',$data);
$this->template->render();
}

It's your routing configured right?,类似于$route[“page/(:any)”]=“page/$1”;所以(:any)-是url中的任意参数,$1-将该参数放入您的url中controller@rajukc47你可以吗!点击第二个链接后粘贴你的URL。