CodeIgniter Forums
Pagination problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Pagination problems (/thread-11184.html)

Pages: 1 2


Pagination problems - El Forum - 08-29-2008

[eluser]buckboru[/eluser]
Hi,
I have been looking at examples of using pagination. I am trying to implement this but i'm having some issues. Basically i get an error on this
$config['total_rows'] = $this->db->count_all('tstmis.phoned01');
saying that Call to a member function count_all() on a non-object

This is what my controller looks like
Code:
<?php
class Phonelist extends Controller
{
    function index()
    {
        //this gives us redirect
        $this->load->helper('url');
                // load pagination class
           $this->load->library('pagination');
           $config['base_url'] = base_url().'index.php/phonelist/list_users/';
        $config['total_rows'] = $this->db->count_all('tstmis.phoned01');
        $config['per_page'] = '5';
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);

        redirect('phonelist/list_users');
    }
    
    function list_users()
    {
    
        $this->load->database();
        $this->load->model('phone_model');
        $data['phonelist'] = $this->phone_model->get_phonelist();
        
        // This gives us anchor() - see the view at the end
        $this->load->helper('url');
         $this->load->view('phonelist_view', $data);
    }
    
    function view_job($id = false)
    {
        $this->load->helper('url');
        if (!$id) redirect ('jobs/list_jobs');
        
        $this->load->database();
        $this->load->model('jobs_model');
        $data['jobs'] = $this->jobs_model->get_job($id);
        
        $this->load->view('job_view',$data);
    }
}
Below works fine in my model
Code:
$query = $this->db->get('tstmis.phoned01');
    foreach ($query->result_array() as $row)
    {
      $result[] = $row;
    }
    
        return $result;
Any ideas?

Thanks


Pagination problems - El Forum - 08-29-2008

[eluser]Thorpe Obazee[/eluser]
[quote author="buckboru" date="1220045396"]
Below works fine in my model
Code:
$query = $this->db->get('tstmis.phoned01');
    foreach ($query->result_array() as $row)
    {
      $result[] = $row;
    }
    
        return $result;
Any ideas?

Thanks[/quote]

Sorry but I don't know where this comes in. where in the controller do you call this?


Pagination problems - El Forum - 08-29-2008

[eluser]buckboru[/eluser]
This comes from my Model controller. The whole code being
&lt;?php
class Phone_model extends Model
{
function get_phoneList()
{
$query = $this->db->get('tstmis.phoned01');
foreach ($query->result_array() as $row)
{
$result[] = $row;
}

return $result;
}


}


Pagination problems - El Forum - 08-29-2008

[eluser]Thorpe Obazee[/eluser]
[quote author="buckboru" date="1220045396"]
&lt;?php

$this->load->library('pagination');
$this->load->database();
$config['base_url'] = base_url().'index.php/phonelist/list_users/';
$config['total_rows'] = $this->db->count_all('tstmis.phoned01');[/quote]

try loading the database library first.


Pagination problems - El Forum - 08-29-2008

[eluser]buckboru[/eluser]
Well that made progress, but I still have a problem.
I am accessing a DB2 database sitting on an IBM AS400.
I have noticed that when I do something like this
<td>&lt;?=$row['LAST_NAME']?&gt;</td>
<td>&lt;?=$row['FIRST_NAME']?&gt;</td>
<td>&lt;?=$row['DEPARTMENT']?&gt;</td>
<td>&lt;?=$row['EXTENSION']?&gt;</td>

I have to have the field name in UPPERCASE otherwise i receive a
Severity: Notice

Message: Use of undefined constant DB2_AUTOCOMMMIT_ON - assumed 'DB2_AUTOCOMMMIT_ON'

Filename: db2c/db2c_driver.php

I am know receiving this error on the

$config['total_rows'] = $this->db->count_all('TSTMIS.PHONED01');


Pagination problems - El Forum - 08-29-2008

[eluser]Thorpe Obazee[/eluser]
DB2?

I really don't know about that. I didn't even know CI has a driver for DB2.


Pagination problems - El Forum - 08-29-2008

[eluser]buckboru[/eluser]
Yeah, someone wrote one that can be found in the WIKI.

Thanks for your help. I have made some progress. Maybe someone else will chime in.


Pagination problems - El Forum - 08-29-2008

[eluser]Thorpe Obazee[/eluser]
You mean this one?
http://codeigniter.com/wiki/DB2_Database_Driver/

It's built for CI 1.5.4

Somehow, it might not be updated anymore for 1.6.3


Pagination problems - El Forum - 08-29-2008

[eluser]buckboru[/eluser]
Yep, thats the one.
I hadn't realized it was written for an older version.


Pagination problems - El Forum - 08-29-2008

[eluser]buckboru[/eluser]
Let me run this by you as i've been debugging and debugging trying to make heads or tails of the problem.

In my db2c.driver.php
Count_all()
Code:
function count_all($table = '')
    {
        if ($table == '') {
            return '0';
        }

        $query = $this->query("SELECT COUNT(*) AS numrows FROM " . $this->dbprefix.$table );
        //$query = $this->query("SELECT COUNT(*) AS numrows FROM `" . $this->dbprefix.$table . "`");
        if ($query->num_rows() == 0) {
            return '0';
        }

        $row = $query->row();

        return $row->numrows;
    }
When i run debug $row shows as an object of stdClass- Inside of that i see NUMROWS with a value of 24(24 is the number of records in my database file) So these means it is actually executing the query and getting results.
However it blows on the next line return$row->numrows with a message of
Undefined property: stdClass::$numrows

any thoughts or guidance as to what to look for.