Welcome Guest, Not a member yet? Register   Sign In
Pagination filtering
#1

[eluser]fdog[/eluser]
I have a form that creates a pagination with a sql result.

View:
Code:
<form action="http://localhost/index.php/results" method="post">
                            
<label>filter 1 </label>                            
                            
<select name="filter1" id = "filter1" >
<option value="0">-- Any--</option>
<option value="1">value 1</option>
<option value="2">value2</option>
</select>

<label >Filter 2</label><br />
<select name="filter2" id = "filter2">
<option value="0">-- Any--</option>
<option value="1">value 1</option>
<option value="2">value2</option>
</select>
&lt;input type="submit" name="submit" value="submit" /&gt;

Controller:
Code:
$where = array(
        'filter1'=> $this->input->post('filter1'),  
        'filter2'=> $this->input->post('filter2')
);

I use the $where to make the sql query. Pagination is created correctly, but I lose the filter values when the pag. links are clicked.
Should I use sessions to keep the $where values or is there an easier way?

Thanks.
#2

[eluser]fdog[/eluser]
I solved it doing the following:

Code:
// save my $where array created from $_POST in session
$this->session->set_userdata($where);

//reassign the array values
$where['filter1'] = $this->session->userdata('filter1');
$where['filter2'] = $this->session->userdata('filter2');

That way I keep the SQL query the same and don't mess with the pagination.
#3

[eluser]skunkbad[/eluser]
Don't forget that you need to be able to turn off your filter to see the unfiltered results.
#4

[eluser]Jondolar[/eluser]
I have thought about either using sessions or just making really long urls to support pagination and filters and sort orders and I'm still struggling with which way to go (and I'm running out of time).

One benefit to using urls is that google (et. al.) will index more pages. For example, if you have a page with 10 records with several links that set filters then not only will google index the default page, but it will index the page with the filters set as well. It will also do it for your pages 2, 3, 4, etc. The problem is that you may get really complex and long urls such as:
/controller/method/id/page/2/filter1/active/filter2/unassigned/sort/name

Your way is cleaner, keep the filters in a session. However, no search engine will be able to set/use those settings to find the same content filtered.
#5

[eluser]fdog[/eluser]
[quote author="Jondolar" date="1249692313"]
The problem is that you may get really complex and long urls such as:
/controller/method/id/page/2/filter1/active/filter2/unassigned/sort/name
[/quote]

My first try was doing exactly that. But it was too much trouble to make it work correctly. I ended up with a lot of bugs Tongue

If you manage to get that working, please do share.
#6

[eluser]Jondolar[/eluser]
Truth is, I think I'm going to do the same as you. Just not sure until I get there and start coding it.
#7

[eluser]dgreenhouse[/eluser]
I really don't like the pagination class that comes with CI - it's very counter-intuitive and cumbersome. (urls look bad too)

That said...

I'm working on a pagination class (actually a function) that's fast and easy to work with. It's quickly becoming a very useful widget.

After I've gotten it ready for use (soon), I'll post the code (with examples) for others to have a "look see."

As far as the "goto page" urls are concerned, I've simplified it tremendously.

Its output is very customizable like:

The following depicts one of the links in the pagination widget output as it could be rendered. There's also a css file that comes with the code.

Code:
<a href="search/results/page/30">30</a>
-OR-
<a href="js:gotoPage(30)">30</a>
{js == javascript}
-OR-
Left to the imagination…

That's it! Return the results for page 30 – period!

When the user navigates to a page, the controller code determines what the query offset is from the passed in var and the values retrieved from the session var.


Easy peazy; lemon squeazy...
#9

[eluser]CARP[/eluser]
does anyone (maybe @fdog) know how much can be stored with set_userdata() ?
I guess it is the most practical/quickest solution to this problem (I'm having a similar issue)




Theme © iAndrew 2016 - Forum software by © MyBB