Pagination WHERE ? - solidcodes - 12-23-2015
Hi guys,
Is the built-in pagination class can handle pagination with WHERE condition?
example codes;
Code: public function fetch_blog_by_user($limit, $start, $id2) {
$q = $this->db->select('blog_id, user_id, title')
->from($this->table_name)
->where('user_id', $id2)
->limit($limit, $start)
->get();
if ($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
thanks in advance.
RE: Pagination WHERE ? - Martin7483 - 12-23-2015
Don't see why it wouldn't be possible.
RE: Pagination WHERE ? - solidcodes - 12-23-2015
@Martin
thanks for the answer.
But why this pagination of mine not showing up the pagination link?
controller:
Code: public function ved_blog()
{
$config = array();
$config['base_url'] = base_url() . "front/ved_blog/";
$config['total_rows'] = $this->blog_mdl->count_records($this->auth_user_id);
$config['per_page'] = 3;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
//$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$page = $this->uri->segment(3, 0);
$id = $this->uri->segment(3, 0);
if($id==0)
{
//display all related blog written by the author
//offer option button to delete.
if( $this->require_min_level(1) )
{
$this->load->helper('array_object');
$this->load->helper('utility');
$data_results = $this->blog_mdl->fetch_blog_by_user($config["per_page"], $page, $this->auth_user_id);
//show_data($data_results);
$data_results2 = object2Array($data_results);
//show_data($data_results2);
$this->view_data['results'] = $data_results2;
$this->view_data['links'] = $this->pagination->create_links();
$this->dryview($header='member/header', $msg='Members CPanel', $menu='member/menu', $content='blog/ved', $footer='empty', $master='member/member_master');
}
else
{
//Just do nothing
}
}
else
{
//Delete the record
if($this->blog_mdl->delete_rec($id))
{
$this->session->set_flashdata('flash_msg', 'Record successfully deleted.');
redirect( base_url(). 'front/cpanel');
}
else
{
$this->session->set_flashdata('flash_msg', 'Sorry record deletion failed.');
redirect( base_url(). 'front/cpanel');
}
}
}
model methods:
Code: public function count_records($user_id) {
$q = $this->db->select('user_id')
->from($this->table_name)
->where('user_id', $user_id)
->get();
return $this->db->count_all_results(); // Produces an integer, like 17
}
public function fetch_blog_by_user($limit, $start, $id2) {
$q = $this->db->select('blog_id, user_id, title')
->from($this->table_name)
->where('user_id', $id2)
->limit($limit, $start)
->get();
if ($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
view:
Code: <center><h2>View, Edit or Delete a blog</h2></center>
<?php
foreach ($results as $result) {
?>
<div id="list">
<b><?php echo $result['title'] ?></b><br>
<a href="<?php echo base_url(); ?>front/view_blog/<?php echo $result['blog_id'] ?>">View</a> |
<a href="<?php echo base_url(); ?>front/edit_blog/<?php echo $result['blog_id'] ?>">Edit</a> |
<a href="<?php echo base_url(); ?>front/ved_blog/<?php echo $result['blog_id'] ?>">Delete</a>
</div>
<hr>
<?php } ?>
<?php
echo $links;
Actually there is no error message.
pagination is autoloaded in autoload.php
The only problem is, it is not showing the pagination link.
Can you help me spot the not?
RE: Pagination WHERE ? - Martin7483 - 12-31-2015
Have you done a var_dump of $this->pagination->create_links() ?
|