Welcome Guest, Not a member yet? Register   Sign In
pagination and sessions
#1

[eluser]atomp3[/eluser]
Hello

Pagination wotks fine if I have static query, but what about query with 'where and order'? Do I have to store them in sessions? When I change pages query returns to default.

Lets say I have form where I can set dates for filtering and result has to be paginate? How to set that?

Thanks.
#2

[eluser]PowerCode[/eluser]
For this, you'll need to use query strings (even clean urls will do, but can cause problems when certain parameters are optional). Well, that's how I've seen many major websites doing it.

You could have something like this,

www.yoursite.com/search/?query=something&sortby=asc&page=4

Using the information from the query string, a SQL query can be constructed. You can use the page parameter to decide upon the page you want displayed.

One thing to remember is that the pagination links have to be generated based on the current query URL.
#3

[eluser]xwero[/eluser]
No one prevents you to have a variable base_url.
Code:
$uri = $this->uri->uri_string();
if(is_numeric(end($this->uri->segment_array())))
{
   $uri = implode('/',array_slice($this->uri->segment_array(),0,-1)));
}

$config['base_url'] = $this->config->site_url($uri);
This example assumes there is no numeric segment at the end other than the pagination segment.
#4

[eluser]Michael Wales[/eluser]
The first question is: is the end user allowed to change the WHERE and ORDER_BY parameters? If not, they would just become part of the model that returns your result set.
#5

[eluser]atomp3[/eluser]
Parameters are being sent by $_POST so maybe store them in a sessions? Any other ideas? Pagination class should be constructed to handle that not only basic stuff.
#6

[eluser]atomp3[/eluser]
[quote author="Michael Wales" date="1235678374"]The first question is: is the end user allowed to change the WHERE and ORDER_BY parameters? If not, they would just become part of the model that returns your result set.[/quote]

Yes end user change that and result should be paginated
#7

[eluser]xwero[/eluser]
[quote author="atomp3" date="1235678413"]Parameters are being sent by $_POST so maybe store them in a sessions? Any other ideas? Pagination class should be constructed to handle that not only basic stuff.[/quote]
I would go for get instead of post because storing sorting parameters for a page in a session will linger in the session if the user decides to go other pages. By keeping it in the url you don't have that problem.
#8

[eluser]Michael Wales[/eluser]
Well, as others have mentioned you could use the URL (which, personally, I think would result in a ugly URL) or you could use the session.

I would probably use a flash session variable for this - and persist that flash variable each time a pagination page is loaded. This will ensure, if a user visits a non-pagination page, that the value is destroyed.
#9

[eluser]Evil Wizard[/eluser]
you could always store them in the

Code:
$this->session->set_userdata('sort_by', $strSortColumn);
$this->session->set_userdata('sort_order', $strSortOrder);

and access them via

Code:
$this->session->userdata('sort_by');
$this->session->userdata('sort_order');

but then you will need to overwrite them in the event of a new post
#10

[eluser]atomp3[/eluser]
[quote author="Evil Wizard" date="1235680467"]you could always store them in the

Code:
$this->session->set_userdata('sort_by', $strSortColumn);
$this->session->set_userdata('sort_order', $strSortOrder);

and access them via

Code:
$this->session->userdata('sort_by');
$this->session->userdata('sort_order');

but then you will need to overwrite them in the event of a new post[/quote]


With sessions works fine thanks!




Theme © iAndrew 2016 - Forum software by © MyBB