CodeIgniter Forums
change GET query string - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: change GET query string (/showthread.php?tid=67170)

Pages: 1 2


RE: change GET query string - Wouter60 - 01-26-2017

Another way to solve this, is assigning a default value to the fields. You probably let the user select the brand from a set of radiobuttons or a dropdown list. If no brand is selected, make the radiobutton "All brands" default (value "all"). Or in a dropdown list, set the default value to "all" with label "Select a brand...".
Now, when your form is transmitted, the get string has no empty options.
In the controller, check if the value of brand == 'all'. If so, you don't need a where clause in your query builder for that option.


RE: change GET query string - ivantcholakov - 01-26-2017

Code:
$query = array(
    'brand' => '',
    'model' => 'a',
);

$query = http_build_query(array_filter($query, 'strlen'));

$url = 'http://www.example.com'.($query != '' ? '?'.$query : '');

echo $url;