Codeigniter中每个页面上的分页

时间:2018-11-08 08:51:13

标签: codeigniter pdf pdf-generation

我希望每个打印页面上显示8个条目。但是我的问题是我在第一页上只得到8个条目,但是我的数据库上却有18个条目...当我单击第二页时,它显示未定义的变量错误..第一页工作正常..以下我附有错误截图(当我单击第二页时).....

enter image description here型号:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mdl_pagination extends CI_Model {

 function __construct(){
  parent::__construct();
 }

 function countcountry(){
  $Search = $this->input->post('Search');
 $this->db->where('billno', $Search);
  $this->db->select('*');
  $this->db->from('salesitem');
   $this->db->join('salesbill', 'salesbill.no = salesitem.billno','left outer');
   $this->db->join('parmaster','parmaster.Pcode = salesbill.partyname','left outer');
   $this->db->join('itemmaster','itemmaster.itcode = salesitem.Product_Code','left outer');
$query = $this->db->get();
  return $query->num_rows();           // return total number of country
 }

 function getcountries($limit,$offset){
     $Search = $this->input->post('Search');
 $this->db->where('billno', $Search);
  $this->db->select('*');
  $this->db->from('salesitem');
   $this->db->join('salesbill', 'salesbill.no = salesitem.billno','left outer');
   $this->db->join('parmaster','parmaster.Pcode = salesbill.partyname','left outer');
   $this->db->join('itemmaster','itemmaster.itcode = salesitem.Product_Code','left outer');
   $offset = $this->uri->segment(3);
$this->db->limit(8, $offset);
$query = $this->db->get()->result_array();
        return $query; 
 }

}

控制器代码:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pagination extends CI_Controller {

 function __construct(){
  parent::__construct();
  $this->load->model('mdl_pagination');
  $this->load->library('table');
  $this->load->helper("url");
 }

 public function country($page=null)
 {
  $this->load->library('pagination');

  $config['base_url'] = 'http://localhost/Yuva1/pagination/country/';    // url of the page
  $config['total_rows'] = $this->mdl_pagination->countcountry(); //get total number of records 
  $config['per_page'] = 8; 
   // define how many records on page
  $config['uri_segment'] = 3;

  $this->pagination->initialize($config);
   $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

  $query = $this->mdl_pagination->getcountries($config['per_page'],$page);
  $data["links"] = $this->pagination->create_links();

        $data['query'] = $query;
  $this->load->view('Inventory/Bill_Print1', $data);
 }

}

我也有一个疑问,除了分页概念,每页上只有8个条目(不带链接)是否有可能,因为我希望它可以在打印账单中实现

1 个答案:

答案 0 :(得分:0)

您当前在偏移量中使用的数组也有$page,因此您无需定义URI段。容易使用。 像这样编辑您的县功能。

public function country($page=0)
{
  $this->load->library('pagination');

  $config['base_url'] = 'http://localhost/Yuva1/pagination/country/';    // url of the page
  $config['total_rows'] = $this->mdl_pagination->countcountry(); //get total number of records 
  $config['per_page'] = 8; 
  $config['cur_tag_open']  = '&nbsp;<a class="current">';
  $config['uri_segment'] = 3;
  $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
  $config['cur_tag_close'] = '</a>';
  $this->pagination->initialize($config);    
  $query = $this->mdl_pagination->getcountries(8,$page);
  $data["links"] = $this->pagination->create_links();
  $data['query'] = $query;
  $this->load->view('Inventory/Bill_Print1', $data);
 }