CodeIgniter Forums
Pagination start at specific id - 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: Pagination start at specific id (/showthread.php?tid=20300)



Pagination start at specific id - El Forum - 07-05-2009

[eluser]teuneboon[/eluser]
Hello,
I have a program that handles a big list of companies. Each company has a specific id. What I have now is just a list with pagination. But what I want is that people will be able to fill in the company id and than that company gets on top of the page, or that it finds the page that company is on. I first wanted to try it by just making my 3rd uri segment to the id of the company, but then I though of it that for example when 3rd uri segment is 20, the first company id is 35. Not all ids are taken. Anyone knows a solution for this?


Pagination start at specific id - El Forum - 07-05-2009

[eluser]TheFuzzy0ne[/eluser]
You could always calculate the position of the company in the table, and then calculate the page number based on that.


Pagination start at specific id - El Forum - 07-05-2009

[eluser]teuneboon[/eluser]
[quote author="TheFuzzy0ne" date="1246838661"]You could always calculate the position of the company in the table, and then calculate the page number based on that.[/quote]
Yes, but how do I do that again? XD


Pagination start at specific id - El Forum - 07-06-2009

[eluser]TheFuzzy0ne[/eluser]
To ascertain the position in the table, something like this should work:

Code:
$results_per_page = 15;
$id = 25;

$this->db->select('COUNT(*) AS count', FALSE);
$this->db->where('id <=', $id);
$this->db->order_by('id');
$this->db->get('companies');
$res = $this->db->get($this->table);
$res = $res->row_array();

$position = $res['count'];
$page_num = ceil($position / $results_per_page);

The largest block of code can easily be exported to a model method.


Pagination start at specific id - El Forum - 07-06-2009

[eluser]teuneboon[/eluser]
Ty,
I'll try this, if it works I'll edit this post Wink

EDIT: Thanks, it works like a charm Smile