Welcome Guest, Not a member yet? Register   Sign In
Pagination Problem: First and previous are not displayed
#1

[eluser]Unknown[/eluser]
When trying to use pagination I don't get the first or the next even using the user_guide sample code.

Code:
<?php
class Pagination_test extends Controller {
    
    function index(){        

        $this->load->library('pagination');
        
        $config['base_url'] = 'http://example.com/index.php/test/page/';
        $config['total_rows'] = '200';
        $config['per_page'] = '20';

        $config['first_link'] = 'First';
        $config['last_link'] = 'Last';

        $this->pagination->initialize($config);
        
        echo $this->pagination->create_links();
        
    }
}

?>

Output:
&nbsp;<strong>1</strong>&nbsp;<a href="http://example.com/index.php/test/page/20">2</a>&nbsp;<a href="http://example.com/index.php/test/page/40">3</a>&nbsp;<a href="http://example.com/index.php/test/page/20">&gt;</a>&nbsp;&nbsp;<a href="http://example.com/index.php/test/page/180">Last</a>

I searched the forums but didn't find any post that helped. The frist and last link code was added on to the sample but didn't change the output.

Any ideas what could be wrong?
#2

[eluser]n0xie[/eluser]
[quote author="nemesis43" date="1255999551"]
Output:
&nbsp;<strong>1</strong>&nbsp;<a href="http://example.com/index.php/test/page/20">2</a>&nbsp;<a href="http://example.com/index.php/test/page/40">3</a>&nbsp;<a href="http://example.com/index.php/test/page/20">&gt;</a>&nbsp;&nbsp;<a href="http://example.com/index.php/test/page/180">Last</a>
[/quote]
Isn't this exactly what you want? :-?
#3

[eluser]Unknown[/eluser]
I want it to look the this. Same as it does in the user guide sample.

<a href="http://automation.chw.edu/test_patching/patching/pagination_test/next/180">First</a>&nbsp;<a href="http://automation.chw.edu/test_patching/patching/pagination_test/next/20">&lt;</a>&nbsp;<strong>1</strong>&nbsp;<a href="http://automation.chw.edu/test_patching/patching/pagination_test/next/20">2</a>&nbsp;<a href="http://automation.chw.edu/test_patching/patching/pagination_test/next/40">3</a>&nbsp;<a href="http://automation.chw.edu/test_patching/patching/pagination_test/next/20">&gt;</a>&nbsp;&nbsp;<a href="http://automation.chw.edu/test_patching/patching/pagination_test/next/180">Last</a>
#4

[eluser]InsiteFX[/eluser]
This is in the CodeIgniter user guide under pagination!

Enjoy
InsiteFX
#5

[eluser]setty[/eluser]
I have same problem, want to add that when i clicking on the second page data is retrieving but link doesn't becomes active, and next hidden links on the pages doesn't appear, and "Next" link doesn't change url
#6

[eluser]InsiteFX[/eluser]
Make sure that your base_url is set right in your application/config/config.php
Code:
« First  < 1 2 3 4 5 >  Last »

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

$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = '200';
$config['per_page'] = '20';

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

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

Enjoy
InsiteFX
#7

[eluser]setty[/eluser]
My config.php:

$config['base_url'] = "http://my.site.ua/";

$config['index_page'] = ""; //Replaced by .htaccess

And I using MY_Language library, so my url at the end looks like http://my.site.ua/en/ or when it's page like http://my.site.ua/en/cc/materials/40

Controller:
function materials()
{
if($this->dx_auth->is_logged_in())
{
// Load pagination library
$this->load->library('pagination');
$this->load->config('pagination');

$config['total_rows'] = $this->db->count_all('stars');

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

// Data
$data['task'] = "list";
$data['title'] = $this->lang->line('cc.site.title');
$data['materials'] = $this->stars->get_stars_info($this->config->item('per_page'), $this->uri->segment(4));


$this->load->view('cc/index', $data);
}
else
{
redirect('cc/login', 'location');
}
}

Config:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$this->CI =& get_instance();

$config['base_url'] = $this->CI->config->item('base_url').$this->CI->lang->lang().'/cc/materials';
$config['per_page'] = 20;

$config['num_links'] = 2;

$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';

$config['first_link'] = 'First';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';

// Last Links
$config['last_link'] = 'Last';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';

// Next Link
$config['next_link'] = '&raquo;';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';

// Previous Link
$config['prev_link'] = '&laquo;';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';

// Current Link
$config['cur_tag_open'] = '<li class="active">';
$config['cur_tag_close'] = '</li>';

// Digit Link
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';

and View
<div id="entries" class="box rba">
<b class="b bt"><em><ins></ins></em><i><ins></ins></i></b>
<div class="fbin">
<h3>Список материалов</h3>
<div id="filter">

</div>
<div id="list">
<table class="list-grid" cellpadding="0" cellspacing="0">
<tr class="headline">
<th class="count">№</th>
<th class="id upper">id</th>
<th class="title">Заголовок</th>
<th class="section">Раздел</th>
<th class="category">Категория</th>
<th class="author">Автор</th>
<th class="cdate">Дата создания</th>
<th class="onmain">На главной</th>
<th class="status">Опубликовано</th>
<th class="actions">Действия</th>
<th class="check"></th>
</tr>
&lt;?php
$count = 1;
foreach($materials as $row) { ?&gt;
<tr class="&lt;?php if(($count%2) == 0){ echo 'row2'; } else { echo 'row1'; } ?&gt;">
<td class='count'>&lt;?php echo $count; ?&gt;</td>
<td class='id'>&lt;?php echo $row['id']; ?&gt;</td>
<td class='title'>&lt;?php echo anchor('cc/edit/'.$row['id'], $row['name']); ?&gt;</td>
<td class='section'>&lt;?php ?&gt;</td>
<td class='category'>&lt;?php echo $row['categoryid']; ?&gt;</td>
<td class='author'>setty</td>
<td class='cdate'>19.11.2009</td>
<td class='onmain'>&lt;?php echo $row['onmain']; ?&gt;</td>
<td class='status'></td>
<td class='actions'>
&lt;?php
echo anchor('cc/edit/'.$row['id'], 'Редактировать');
echo anchor('cc/preview/'.$row['id'], 'Просмотр');
echo anchor('cc/delete/'.$row['id'], 'Удалить');
?&gt;
</td>
<td class='check'></td>
</tr>
&lt;?php $count++; }?&gt;
</table>
<div id="bottom-pages">
&lt;?php echo $this->pagination->create_links(); ?&gt;
</div>
</div>
</div>
<b class="b bb"><em><ins></ins></em><i><ins></ins></i></b>
</div>


URLs at the end looks like http://my.site.ua/en/cc/materials/40 and data retrieving but pagination not change.
#8

[eluser]InsiteFX[/eluser]
You should be building the config in your controller like so, then pass it in.

Code:
var $config = array();

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

    $config['base_url'] = 'http://example.com/index.php/test/page/';
    $config['total_rows'] = '200';
    $config['per_page'] = '20';

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

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

Enjoy
InsiteFX
#9

[eluser]setty[/eluser]
And what? It change nothing! Why are you thinking that i didn't try it?
#10

[eluser]squarebones[/eluser]
Code:
$config['num_links'] = '1';

As an example. This sets the number of links between the current page and the next/previous links. With a number of pages over 2, if you are on the first page, the Last link will appear. If you are on the last page, the First link will appear.

They don't always appear at the same time, however. Perhaps if the results are over a certain number of pages? Yes. If you are on page 3 or over, the first link will appear allowing you to skip to page 1 (which is not displayed because num_links is set so low), and the Last link will appear for the same reason. It doesn't mention this in the guide, but you can easily play with all the $config values once you have some goodly amount of data in your db. To really see it in action, set the appropriate values very low:

Code:
$config['per_page'] = '5';
$config['uri_segment'] = '4';
$config['num_links'] = '1';

Viola! (or violá, depending upon your geographical humor).




Theme © iAndrew 2016 - Forum software by © MyBB