Say you have a search form like so:
<form action="<?php $_PHP_SELF ?>" method="GET">
Some filter:
<select name="filter">
<option value="">Any value</option>
<option value="1">value is 1</option>
etc...
</select>
<input type="submit" value="Search">
</form>
and your index page looks like this:
<?php
if($_GET['filter']){
$sql = 'SELECT * FROM table WHERE value=' . $_GET['filter'];
/* prepare, execute blah blah blah etc etc etc */
include 'results.php';
exit();
}
include 'searchform.php';
?>
Which would work perfectly well if a filter is set. But if not I'd like it to show all results, instead it just keeps the page on the searchform. If I change it to if($_GET['filiter'] or $_GET['filter'] == ""){
it (logically) just gets all the results unfiltered and ignores the searchform. Any solutions?
NOTE:
I know that I could set a hidden input type like <input type="hidden" name="hidden" value="true">
and instead of checking the filter using if($_GET['hidden'] == 'true'){
but then it would be visible in the URL and I don't want that. Nor do I want to just use POST
because then the filter won't be visible, and I'd prefer that if someone wants to just change the filter in the URL they can instead of going back to the searchform.
NOTE 2 I use PDO to prepare and execute, however that has nothing to do with the issue, hence why I haven't provided it