Welcome Guest, Not a member yet? Register   Sign In
Calling data from pagination result
#1

[eluser]mflammia[/eluser]
Hi All,

Just wondering what I am doing wrong here.

I have the following function in my controller:

Code:
function databaselist()
{
            //pagination
            $config['base_url'] = 'http://127.0.0.1/index.php/site/databaselist';
            $config['total_rows'] = $this->db->get('person')->num_rows();
            $config['per_page'] = 10;
            $config['num_links'] = 20;
            $this->pagination->initialize($config);
            $data['records'] = $this->db->get('person', $config['per_page'], $this->uri->segment(3));
            echo '<pre>';
            print_r ($data['records']);
            echo '</pre>';
            $this->load->view('databaselist',$data);
            
}

The output of which is:

Code:
CI_DB_mysql_result Object
(
    [conn_id] => Resource id #30
    [result_id] => Resource id #42
    [result_array] => Array
        (
        )

    [result_object] => Array
        (
        )

    [custom_result_object] => Array
        (
        )

    [current_row] => 0
    [num_rows] => 10
    [row_data] =>
)

Now this is where I am going wrong but from the few places I have read how to configure I should be able to call the data with something like the following:

Code:
&lt;?PHP foreach($records as $data){
            echo '<pre>';
            print_r ($data);
            echo '</pre>';
            echo $data->first_name;
        }
        ?&gt;

But this is producing a
Quote:Message: Trying to get property of non-object
error.

I see its because of the way $result is constructed but I don't know how to call / code getting the right data?

Thanks in advance.
#2

[eluser]Aken[/eluser]
You need to use a result method after using get() or similar. See the get() method example here.
#3

[eluser]mflammia[/eluser]
Great! Thanks for the reply, that sorted it.

Code:
&lt;?PHP foreach($records->result() as $data){
            echo '<pre>';
            print_r ($data);
            echo '</pre>';
            echo $data->first_name;
        }
        ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB