[eluser]solid9[/eluser]
Hi guys
I created these codes below for pagination,
Code: //Edit and Delete paginator
function ed_paginator() {
$this->data['header_message'] = '';
if($this->ion_auth->logged_in() && !$this->ion_auth->is_admin()) {
$this->data['member_menu'] = $this->load->view('member_menu', null, TRUE);
} else {
$this->data['member_menu'] = '';
}
$this->data['header'] = $this->load->view('header', $this->data, TRUE);
$tmpl = array (
'table_open' => '<table border="0" cellpadding="4" cellspacing="0" class="ed">',
'heading_row_start' => '<tr>',
'heading_row_end' => '</tr>',
'heading_cell_start' => '<th class="ed">',
'heading_cell_end' => '</th>',
'row_start' => '<tr>',
'row_end' => '</tr>',
'cell_start' => '<td class="ed">',
'cell_end' => '</td>',
'row_alt_start' => '<tr>',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td class="ed">',
'cell_alt_end' => '</td>',
'table_close' => '</table>'
);
$this->table->set_template($tmpl);
$userid = $this->session->userdata('user_id');
$this->table->set_heading('Id', 'Offering', 'edit', 'delete');
$config['base_url'] = 'http://barterswapping.com/main/ed_paginator';
$config['total_rows'] = $this->db->select('swap.swapid, swap.offering')
->from('swap')
->join('users_swap', 'users_swap.swap_id=swap.swapid')
->where('users_swap.user_id', $userid)
->get();
$config['per_page'] = 5;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->data['records'] = $this->db->select('swap.swapid, swap.offering')
->from('swap')
->join('users_swap', 'users_swap.swap_id=swap.swapid')
->where('users_swap.user_id', $userid)
->limit($config['per_page'])
->get();
$this->data['midnav'] = $this->load->view('body_m_frontpage', $this->data, TRUE);
$this->load->view('front_page', $this->data);
}
[code]
The error is,
[code]
Object of class CI_DB_mysql_result could not be converted to string
What could be the reason for the error?
Thanks in advanced
[eluser]oliur[/eluser]
It basically means you can't convert a query object to result.
To do that you need to use result() or result_array() method.
In your case, just add result() at the end like this:
more information here
[eluser]solid9[/eluser]
I already did what you said.
But I got a new error.
Code: Fatal error: Unsupported operand types in /home/www/mysite.com/system/libraries/Pagination.php on line 124
by the way here is the newly modified pagination method
Code: //Edit and Delete paginator
function ed_paginator() {
$this->data['header_message'] = '';
if($this->ion_auth->logged_in() && !$this->ion_auth->is_admin()) {
$this->data['member_menu'] = $this->load->view('member_menu', null, TRUE);
} else {
$this->data['member_menu'] = '';
}
$this->data['header'] = $this->load->view('header', $this->data, TRUE);
$tmpl = array (
'table_open' => '<table border="0" cellpadding="4" cellspacing="0" class="ed">',
'heading_row_start' => '<tr>',
'heading_row_end' => '</tr>',
'heading_cell_start' => '<th class="ed">',
'heading_cell_end' => '</th>',
'row_start' => '<tr>',
'row_end' => '</tr>',
'cell_start' => '<td class="ed">',
'cell_end' => '</td>',
'row_alt_start' => '<tr>',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td class="ed">',
'cell_alt_end' => '</td>',
'table_close' => '</table>'
);
$this->table->set_template($tmpl);
$userid = $this->session->userdata('user_id');
$this->table->set_heading('Id', 'Offering', 'edit', 'delete');
$config['base_url'] = 'http://barterswapping.com/main/ed_paginator';
//$config['total_rows'] = $this->db->get('swap')->num_rows();
$config['total_rows'] = $this->db->select('swap.swapid, swap.offering')
->from('swap')
->join('users_swap', 'users_swap.swap_id=swap.swapid')
->where('users_swap.user_id', $userid)
->get()
->result();
$config['per_page'] = 5;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
//$this->data['records'] = $this->db->get('swap', $config['per_page'], $this->uri->segment(3));
$this->data['records'] = $this->db->select('swap.swapid, swap.offering')
->from('swap')
->join('users_swap', 'users_swap.swap_id=swap.swapid')
->where('users_swap.user_id', $userid)
->limit($config['per_page'], $this->uri->segment(3))
->get()
->result();
$this->data['midnav'] = $this->load->view('body_m_frontpage', $this->data, TRUE);
$this->load->view('front_page', $this->data);
}
I believed the problem is not in the pagination class.
Since I haven't touched it.
I'm not sure if the ->result() is right?
[eluser]oliur[/eluser]
you do not need result() for $config['total_rows'].
It expects an int not an array.
So remove result().
[eluser]solid9[/eluser]
I already remove the ->result()
the same error.
Anyone please.
[eluser]oliur[/eluser]
Sorry I wasn't quite right there.
get() still returns an array of objects and therefore pagination class will still complain.
So, what I suggest you use result() and count returned result using count() or sizeof() functions.
Code: $config['total_rows'] = sizeof($this->db->select('swap.swapid, swap.offering')
->from('swap')
->join('users_swap', 'users_swap.swap_id=swap.swapid')
->where('users_swap.user_id', $userid)
->get()
->result());
[eluser]solid9[/eluser]
Sometimes I don't use my brain.
Anyway I fix my own problem.
Here is the working codes,
Code: $query = $this->db->select('swap.swapid, swap.offering')
->from('swap')
->join('users_swap', 'users_swap.swap_id=swap.swapid')
->where('users_swap.user_id', $userid)
->get();
$config['total_rows'] = $query->num_rows();
Problem solved.
[eluser]oliur[/eluser]
well i was going to suggest this to you but as you know there are more ways to solve a problem.
Pagination class was simply complaining as you were passing an array when it was expecting a number.
Weldone you.
|