Search & Pagination - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Search & Pagination (/showthread.php?tid=31399) Pages:
1
2
|
Search & Pagination - El Forum - 06-17-2010 [eluser]Vasi[/eluser] Hi, I have a form with 3 inputs (1 text, 2 drop-downs). I have no problem performing the search and in displaying the pagination, the problem is in storing my POST values, on which the search query is based. If I store them in the session, I keep getting the same result (of course) or nothing at all. So the questions is this: How do I reset the session variables after I complete my search? Or: If the session doesn't do the trick on storing the POST values, how should I rebuild my search module. View Code: <?php Controller Code: ... Search & Pagination - El Forum - 06-17-2010 [eluser]Twisted1919[/eluser] Salut You could try like this : Code: function some_function($criteriul_1='all',$criteriul_2='all',$criteriul3='all') Code: $config['base_url'] = site_url().'/controller/method/'.$criteriul_1.'/'.$criteriul_2.'/'.$criteriul_3.'/; The model function needs to look something like : Code: if($criteriul_1 != 'all'){ This example is only as an idea, just open your eyes, you will get it . Let me know if you have question . Search & Pagination - El Forum - 06-17-2010 [eluser]pickupman[/eluser] You can shorten the syntax using ternary operators. Code: $localitate = ($this->session->userdata('search_loc')) ? $this->session->userdata('search_loc') : 0; Whenever you want to paginate search results you can do it one of 2 ways. 1.) Store the search params in the session like you are doing now. And then pass to your model for the results. 2.) Store the params in the DB. This is how it is done here on the boards. When you search, the terms are added to the DB, then the DB returns a record number, and you redirect the user to site.com/search/results/IDNumber. Similar to sessions you can add a timestamp to the record, and purge any searches older than a certain time. This allows allows you to cache the result of the search if someone else search the same term in a given time period. Search & Pagination - El Forum - 06-17-2010 [eluser]Vasi[/eluser] Thanks for the support guys! I really appreciate it. Quote:1.) Store the search params in the session like you are doing now. And then pass to your I am storing them now, but how do I unset them for other searches? Thanks again Search & Pagination - El Forum - 06-17-2010 [eluser]siubie[/eluser] unset the session data $this->session->unset_userdata($array_items); *from user guide Search & Pagination - El Forum - 06-18-2010 [eluser]Vasi[/eluser] Sorry, what I really meant to say was: "When should I unset the session, because if I unset it after the search result is displayed, I loose the query for the other pages (of the pagination)." Search & Pagination - El Forum - 06-18-2010 [eluser]n0xie[/eluser] Why not just use GET? Makes more sense with paginating and filtering... Search & Pagination - El Forum - 06-18-2010 [eluser]Vasi[/eluser] [quote author="n0xie" date="1276868158"]Why not just use GET? Makes more sense with paginating and filtering...[/quote] I tried using POST, in my view, like this: Code: if (!empty($_POST)) The problem with this is that I get the right result after two clicks on the search button, on the first click I get zero results. I know why is this happening but I can't seem to find a solution. Thanks again for the reply and support. Cheers! Search & Pagination - El Forum - 06-18-2010 [eluser]pickupman[/eluser] You can do this this by posting form to a do_search() method, unset old data, set new data, and then redirect page to results() method. Search & Pagination - El Forum - 06-19-2010 [eluser]siubie[/eluser] [quote author="Vasi" date="1276864496"]Sorry, what I really meant to say was: "When should I unset the session, because if I unset it after the search result is displayed, I loose the query for the other pages (of the pagination)."[/quote] unset the search data only if there is new search query , if not just continue with the paging |