• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination config problem

#11
[eluser]CI_Newb[/eluser]
[quote author="LuckyFella73" date="1289837599"]The pagination library just need to know how many rows there are
available totally and how many rows you want to display per page
to calculate how many links (pages) to create (and how to set up the pagination-links).

The second query gets the data for the actual page based on the given
values (per page, start page). The query to generate the pagination
links is generally undependent from the query getting the data to display
in your view. You just have to make sure that the num-per-page value and
the "start-from" value in your "view-query" matches with the pagination
config value to get a result set and pagination links that make sense.

Sorry, for I'm no native english speaker it's not so easy to express
clearly what I'm trying to ...[/quote]

Don't apologize, I value all the advice and help I can get Smile

So I tried what you suggested and for some reason, the total_rows query always returns a value of 1 when the second query returns properly.

Pagination is a pita lol

#12
[eluser]ToXXXic[/eluser]
i am having a similar problem which means I get everything else right but the link buttons (prev 1 2 3 next)are not displayed. I get the num_rows as follow:

Code:
class search_model extends Model
{
    public $total_rows=0;
    
    function getCompany($perpage)
    {
        
        
        $this->db->like('name',$this->input->post('search'));
        $this->db->or_like('business',$this->input->post('search'));
        
        $query=$this->db->get('company',$perpage, $this->uri->segment(3));
        $this->total_rows=$query->num_rows();
        
        if($query)
        {
            return $query->result();
        }
        
    }
}

in Controller:

Code:
function viewSearch()
    {
    
    
            $this->load->model('search_model');
        $this->load->library('pagination');
        $this->load->library('table');
        
    

$config['base_url']='http://localhost/index.php/main/viewSearch/';
    
        $config['per_page']='5';
        $config['num_links']=10;
        $config['uri_segment'] =3;
        $config['full_tag_open']='<div id="pagination">';
        $config['full_tag_close']='</div>';
        
        
        $query = $this->search_model->getCompany($config['per_page']);
        $config['total_rows']=$this->search_model->total_rows;
        
        //echo $this->search_model->total_rows;
        
        $this->pagination->initialize($config);
        
        $data['records'] = $query;
        
        $data['main_content']='search_view';
        $this->load->view('includes/master',$data);
        
    
    }

Any idea what might be wrong with what i am doing? appreciate your help Smile

Thanks

#13
[eluser]LuckyFella73[/eluser]
That is strange! The only difference between the 2 model-functions
is the LIMIT statement. And if you get results when limiting the
query you should get results as well when not limiting...

#14
[eluser]CI_Newb[/eluser]
[quote author="LuckyFella73" date="1289844129"]That is strange! The only difference between the 2 model-functions
is the LIMIT statement. And if you get results when limiting the
query you should get results as well when not limiting...[/quote]

Ya I thought the same. I even did a straight copy / paste.

#15
[eluser]LuckyFella73[/eluser]
@ToXXXic

do you get a valid value for total_results? If yes: are you sure you
echo the pagination in your view?
Code:
echo $this->pagination->create_links();
I can't see something wrong looking at you code.



@CI_Newb
Then you'll have to degub a little bit now. I would start with echoing
last query and make tests with phpmyadmin to check if you have an error
somewhere.
Code:
$this->db->last_query();

#16
[eluser]ToXXXic[/eluser]
@ LuckFella73

Thanks for looking into my code. here is my view:

Code:
&lt;?php

$tmpl = array (
  'table_open'          => '<table border="0" cellpadding="0" cellspacing="0">',
  'heading_row_start'   => '<tr class="heading">',
  'heading_row_end'     => '</tr>',
  'heading_cell_start'  => '<th>',
  'heading_cell_end'    => '</th>',
  'row_start'           => '<tr>',
  'row_end'             => '</tr>',
  'cell_start'          => '<td>',
  'cell_end'            => '</td>',
  'row_alt_start'       => '<tr class="alt">',
  'row_alt_end'         => '</tr>',
  'cell_alt_start'      => '<td>',
  'cell_alt_end'        => '</td>',
  'table_close'         => '</table>'
);
$this->table->set_template($tmpl);      


//-- Header Row
$this->table->set_heading('Name', 'Business', 'Country', 'City');

//-- Content Rows
foreach($records as $index => $row)
{
  $this->table->add_row(
    anchor("main/details/$row->id", $row->name),
    $row->business,
    $row->country,
     $row->city
  );
}

//-- Display Table
echo $table = $this->table->generate();

echo $this->pagination->create_links();

?&gt;

#17
[eluser]LuckyFella73[/eluser]
@ToXXXic

What result do you get when "activating":
Code:
echo $this->search_model->total_rows;
in your controller?

I ask because if you get FALSE or less entries than you want to display
per page the pagination won't display.

#18
[eluser]ToXXXic[/eluser]
@LuckyFella,

I get 4 when i echo the total_rows, 4 is the number of
Code:
$config['per_page']='4';
I am not sure, should the total_rows return the total row not the per_page.

Thanks

#19
[eluser]LuckyFella73[/eluser]
"total_rows" should return how many results you have in total.
If you have 100 total_rows and set the config "per_page" to 20
then your pagination creates 5 page-links.
If you set the "per_page" value to 4 and get only 4 total results
then there is no second page and thus the pagination don't show up.

Just check by setting per_page to "1" or "2", then it should be displayed.

#20
[eluser]ToXXXic[/eluser]
hmmm, you are right, but i wonder what i might be doing wrong?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.