Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]Pagination Problem!
#1

[eluser]husni[/eluser]
hello..i am trying to use pagination class..
i have seen the codeigniter tutorials but may be lack of understanding about the coding..
how to put the ['base_url'] actually?
my browser only show the number of pages and the link..
when i click the number..it will be redirect to my another page..
can anyone help me???
this is the only thing shown in my browser..
Quote:1
2
3
>
Last
#2

[eluser]maria clara[/eluser]
can you post your code for debugging?
#3

[eluser]husni[/eluser]
[quote author="maria clara" date="1264601377"]can you post your code for debugging?[/quote]

hi..i found code for pagination in devshed forum..
the problem still the same..the link is appeared..but when i click on the link,it will be redirect to the first page only..

this is the model..
Quote:function getAllReport()
{
$query=$this->db->get('tblreport');

if($query->num_rows()>0){

// return result set as an associative array

return $query->result_array();

}

}

function getReportWhere($field,$param)
{

$this->db->where($field,$param);

$query=$this->db->get('tblreport');

// return result set as an associative array

return $query->result_array();

}

// get 5 rows at a time

function getReport($row)
{

$query=$this->db->get('tblreport',5,$row);

if($query->num_rows()>0)
{

// return result set as an associative array

return $query->result_array();

}

}

// get total number of users

function getNumReport()
{

return $this->db->count_all('tblreport');
echo $this->db->count_all('tblreport');
}

this is the controller file
Quote:<?php
class Paging extends Controller{

function Paging(){

// load controller parent

parent::Controller();

// load 'Users' model

$this->load->model('Helpdesk_model');

}

function display($row=0){

// load pagination library

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

// set pagination parameters

$config['base_url']='http://localhost/helpdesk2/index.php/paging/display/';

$config['total_rows']=$this->Helpdesk_model->getNumReport();

$config['per_page']='5';

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

// store data for being displayed on view file

$data['reports']=$this->Helpdesk_model->getReport($row);

$data['title']='Displaying Report data';

$data['header']='Report List';

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

// load 'testview' view

$this->load->view('report_view',$data);

}

}

?>

this is the view file..
Quote:<html>

<head>

<title><?php echo $title;?></title>

</head>

<body>

<h1>&lt;?php echo $header;?&gt;</h1>

<ul>
&lt;?php foreach($reports as $report):?&gt;
<li>
<p>&lt;?php echo 'Report ID: '.$report['report_id'].' Report Details: '.$report['report_details'];?&gt;</p>
</li>
&lt;?php endforeach;?&gt;
</ul>

<p>&lt;?php echo $links;?&gt;</p>


&lt;/body&gt;

&lt;/html&gt;

can you help me?please..
i provided the view in my browser..
when i click number 2..it still in the page 1..
#4

[eluser]maria clara[/eluser]
do you have an offset value for your pagination??
#5

[eluser]maria clara[/eluser]
try this in your model:
Code:
function getAllReport($num = NULL, $offset = NULL)
  {
      $query=$this->db->get(‘tblreport’);
$query = $this->db->query("SELECT * FROM test WHERE end >= NOW() order by start asc LIMIT $offset, $num");    
    return $query;

      }

and put this in your controller:
Code:
function display($row=0){

      // load pagination library
    
      $this->load->library(‘pagination’);
    
      // set pagination parameters
    
      $config[‘base_url’]=‘http://localhost/helpdesk2/index.php/paging/display/’;
    
      $config[‘total_rows’]=$this->Helpdesk_model->getNumReport();
    
      $config[‘per_page’]=‘5’;
    
      $this->pagination->initialize($config);

// to multiply your offset by your $config[‘per_page’]
//That should get rid of the mysql error if no page is specified too
if (isset($page) && is_int($page))
            {
              $offset = $page * $config['per_page'];
            }
            else
            {
              $offset = 0;
            }
        $data['query'] = $this->Helpdesk_model->get_events(5,$offset);


// store data for being displayed on view file
    
      $data[‘reports’]=$this->Helpdesk_model->getReport($row);
    
      $data[‘title’]=‘Displaying Report data’;
    
      $data[‘header’]=‘Report List’;
    
      $data[‘links’]=$this->pagination->create_links();
    
      // load ‘testview’ view
    
      $this->load->view(‘report_view’,$data);
#6

[eluser]maria clara[/eluser]
you have to put this before your
Code:
....

$config['uri_segment'] = '3'; //<---

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

Passing URI segments to your functions
#7

[eluser]husni[/eluser]
i have put the codes you gave me..
but it still the same..
what is the problem??
#8

[eluser]husni[/eluser]
[quote author="maria clara" date="1264669694"]try this in your model:
Code:
function getAllReport($num = NULL, $offset = NULL)
  {
      $query=$this->db->get(‘tblreport’);
$query = $this->db->query("SELECT * FROM test WHERE end >= NOW() order by start asc LIMIT $offset, $num");    
    return $query;

      }

and put this in your controller:
Code:
function display($row=0){

      // load pagination library
    
      $this->load->library(‘pagination’);
    
      // set pagination parameters
    
      $config[‘base_url’]=‘http://localhost/helpdesk2/index.php/paging/display/’;
    
      $config[‘total_rows’]=$this->Helpdesk_model->getNumReport();
    
      $config[‘per_page’]=‘5’;
    
      $this->pagination->initialize($config);

// to multiply your offset by your $config[‘per_page’]
//That should get rid of the mysql error if no page is specified too
if (isset($page) && is_int($page))
            {
              $offset = $page * $config['per_page'];
            }
            else
            {
              $offset = 0;
            }
        $data['query'] = $this->Helpdesk_model->get_events(5,$offset);


// store data for being displayed on view file
    
      $data[‘reports’]=$this->Helpdesk_model->getReport($row);
    
      $data[‘title’]=‘Displaying Report data’;
    
      $data[‘header’]=‘Report List’;
    
      $data[‘links’]=$this->pagination->create_links();
    
      // load ‘testview’ view
    
      $this->load->view(‘report_view’,$data);
[/quote]

Code:
$data['query'] = $this->Helpdesk_model->get_events(5,$offset);

do i need to echo query??
the get_events function is not in my model..it is getAllReport($num = NULL, $offset = NULL) right??
#9

[eluser]maria clara[/eluser]
i made a mistake change it to this:
Code:
if (isset($page) && is_int($page))
            {
              $offset = ($page-1) * $config['per_page']; //Because if the page is 1 then the offset should be 0
            }
            else
            {
              $offset = 0;
            }



Also try taking this line out of your controller:
Code:
$config['uri_segment'] = '3';


do they satisfy now??
#10

[eluser]maria clara[/eluser]
change the get_events(5,$offset) to getAllReport(5,$offset)




Theme © iAndrew 2016 - Forum software by © MyBB