Welcome Guest, Not a member yet? Register   Sign In
Pagination Problem
#1

[eluser]markdeionwolf[/eluser]
Please help me with this code. it shows the link but the pagination doesn't work.thank you in advance.

class Parts extends Controller
{
function Parts(){

parent::Controller();
$this->load->database();
}

function index()
{
$config['uri_segment'] = 4;

$this->db->select(array('category', 'nmbr', 'description', 'severity_type', 'exp_type', 'cost'));
$this->db->order_by('category asc, description');
$params['parts'] = $this->db->get('database.table')->result_array();

$this->load->library('pagination');

$config['base_url'] = base_url().'index.php/files/parts/index';
$config['total_rows'] = count($params['parts']);
$config['per_page'] = '25';

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

$params['pagination'] = $this->pagination->create_links();

$this->load->view('files/parts_list_view',$params);

}
#2

[eluser]pickupman[/eluser]
Looking at it quickly it appears the code is correct. Could you be more specific by not working? ie Links are generating correctly, but results are not being paginated when click on the links. Or links are not being created.

You may want to try:
Code:
$params['parts'] = $this->db->get('database.table')->result_array();
var_dump($params['parts']);

//Tip
$config['base_url'] = site_url('files/parts/index/'); //site_url will add your index file if set + trailing slash
Is the array being properly returned?

Also, please use the code button in the editor when posting code. It will make it easier to read and copy/paste.
#3

[eluser]markdeionwolf[/eluser]
links are generating correctly but the results are not paginated and the array returns result.
i will try your suggestion. thanks!
#4

[eluser]markdeionwolf[/eluser]
it did not work. here is the code and the error report.

Code:
function index()
    {
    
        $config['uri_segment'] = 4;
        
        $this->db->select(array('category', 'nmbr', 'description', 'severity_type', 'exp_type', 'cost'));
        $this->db->order_by('category asc, description');
        //$this->db->limit(25,$nmbr);
        $params['parts'] = $this->db->get('delwater_MasterDB.item_mstr')->result_array();
        
        $total_rows = $params['parts'];
        
        $this->load->library('pagination');
            
        $config['base_url'] = site_url('files/parts/index/');
        $config['total_rows'] = $total_rows;
        $config['per_page'] = '25';
        
        $this->pagination->initialize($config);
        
        $params['pagination'] = $this->pagination->create_links();
        
        $this->load->view('files/parts_list_view',$params);
    
    }
Fatal error: Unsupported operand types in C:\xampp\htdocs\codeigniter\system\libraries\Pagination.php on line 112
#5

[eluser]orfaust[/eluser]
the error is generated by this code (Pagination.php on line 112)
Code:
$num_pages = ceil($this->total_rows / $this->per_page);
it can't execute the division because one of the operands is not a number.
Since you give 'per_page' an explicit value, $total_rows is probably not a number.
Check your code

EDIT:
(hint) in your first post you wrote:
Code:
$config['total_rows'] = count($params['parts']);
which was correct, instead of
Code:
$total_rows = $params['parts'];
#6

[eluser]markdeionwolf[/eluser]
i already solve the pagination problem.thanks guys!
here is the new code
Code:
function show()
    {
        $config['uri_segment'] = 4;
        
        $start_row = $this->uri->segment(4);
        $per_page = 25;
        
        if (trim($start_row)== ""){
        
            $start_row = 0;
        }
        
        $parts =  $this->_get_parts();
        $total_rows = $parts->num_rows();
        
        $this->load->library('pagination');
        $config['base_url'] = base_url() . 'index.php/files/parts/show';
        $config['total_rows'] = $total_rows;
        $config['per_page'] = $per_page;
        $config['num_links'] = 10;
        $this->pagination->initialize($config);
        
        $this->view_data['pagination'] =  $this->pagination->create_links();
    
        $this->view_data['parts'] = $this->_get_parts_limited($start_row, $per_page);
        
        $this->load->view('files/parts_list_view', $this->view_data);
        
        
    }

How will i add SEARCH in this pagination? thanks in advance!Smile
#7

[eluser]pickupman[/eluser]
You can do this 3 ways.
1. Store the search term in a users session. Then in your DB call use a where/like statement for that session variable.
2. You can encrypt/decrypt the search string into the uri using the [url="http://ellislab.com/codeigniter/user-guide/libraries/encryption.html"]encryption library. You would have to make this be the 4th segment, and move the pagination to 5th segment.

3. Same idea is a number, only md5 the search string, add it to the db, and redirect to a url with the md5 or row id in the string as the 4th segment again. This method is what is used on the forums. This can used if you want to track search terms, keyword frequency, or throttle user searches.




Theme © iAndrew 2016 - Forum software by © MyBB