Welcome Guest, Not a member yet? Register   Sign In
Pagination start at specific id
#1

[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?
#2

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

[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
#4

[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.
#5

[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




Theme © iAndrew 2016 - Forum software by © MyBB