CodeIgniter Forums
codeigniter's pagination offset not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: codeigniter's pagination offset not working (/showthread.php?tid=58002)



codeigniter's pagination offset not working - El Forum - 05-04-2013

[eluser]Blazetama[/eluser]
Hello All,

I have asked this question on stackoverflow, please see this link :

http://stackoverflow.com/questions/16376292/codeigniters-pagination-offset-not-working/16376402?noredirect=1#16376402

Sometimes, i dont get good answer in SO when im talking about CI, so i come here.

Any help will be appreciated, thanks Big Grin


codeigniter's pagination offset not working - El Forum - 05-04-2013

[eluser]TheFuzzy0ne[/eluser]
Are the pagination links being generated as you'd expect? Please paste a few examples of the URLs it's generating.

Does $result['num_rows'] contain a valid value?

What do you mean when you say "the $offset value is true". It should be an integer.


codeigniter's pagination offset not working - El Forum - 05-05-2013

[eluser]Blazetama[/eluser]
[quote author="TheFuzzy0ne" date="1367687740"]Are the pagination links being generated as you'd expect? Please paste a few examples of the URLs it's generating.

Does $result['num_rows'] contain a valid value?

What do you mean when you say "the $offset value is true". It should be an integer.[/quote]

Thanks for your response Big Grin
Yes, the pagination is working as expected (except for the offset).

The example of url when offset is 0 (default value, i check the $offset value by echoing it) :

http://localhost/ci_gabdb/index.php/backend_umat/index -> the index start from 1

When $offset is 10 :

http://localhost/ci_gabdb/index.php/backend_umat/index/10 -> the $offset value is true because the limit is 10 and this is the 2nd page in pagination, but the index start from 1 again.

I tried to echo $result['num_rows'] , it returns a valid (integer) value.

Do you have any idea whats going on here? Thanks



codeigniter's pagination offset not working - El Forum - 05-06-2013

[eluser]rana[/eluser]
[quote author="Blazetama" date="1367762970"]but the index start from 1 again.
[/quote]

Here, by 'index' , did you mean the index of the list you are showing? If so, it is generating ok, you are understanding wrong. To show list number, you will have to do a little tweak like:

for($i=0;$i<count($result);$i++){
$row = $result[$i];
echo "data serial#".($offset+$i)." : ".$row->kelas_id;
}

If your problem in something else, please make it clear. Also, Please share your view code as well.


codeigniter's pagination offset not working - El Forum - 05-06-2013

[eluser]Blazetama[/eluser]
First, i would like to thanks to TheFuzzyOne and Rana who helped me kindly Big Grin

And, i want to say sorry because i made a "stupid" mistake which took me for hours to realize. The pagination is working perfectly, i just forget to use the
Code:
$offset
:

Before -> i use
Code:
$no = 1
:

Code:
$no = 1;
  foreach($data_umat as $list_temp)
  {
   $this->table->add_row(
    $no++,
    $list_temp->nama,
    $list_temp->kelas,
    $list_temp->alamat,
    $list_temp->tanggal_lahir,
    $list_temp->sekolah,
    $list_temp->no_tlpn,
    $list_temp->keterangan
   );
  }

Now (Working) :

Code:
foreach($data_umat as $list_temp)
  {
   $this->table->add_row(
    ++$offset,
    $list_temp->nama,
    $list_temp->kelas,
    $list_temp->alamat,
    $list_temp->tanggal_lahir,
    $list_temp->sekolah,
    $list_temp->no_tlpn,
    $list_temp->keterangan
   );
  }