Stack Exchange
mysqli filter by parameter with show all option
What is the best way to modify this query to show all records if parameter matches for showall, is it normal practise to use:
if (isset($_GET['category']) && $_GET['category'] == 'showall')   ... else ? 

SELECT id, heading, category FROM table WHERE category = %s ORDER BY `date` DESC


The most easy way would probaply be this:
if (isset($_GET['category']) && $_GET['category'] == 'showall'){
execute : SELECT id, heading, category FROM table ORDER BY `date` DESC

} else if(isset($_GET['category']) && $_GET['category'] != 'showall') {

execute : SELECT id, heading, category FROM table WHERE category = %s ORDER BY `date` DESC

}

