2015-11-27 2 views
0

Quelle est la meilleure façon de modifier cette requête pour afficher tous les enregistrements si le paramètre correspond à showall, est-il normal d'utiliser:filtre mysqli par le paramètre avec option Afficher tous

if (isset($_GET['category']) && $_GET['category'] == 'showall') ... else ? 

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

Répondre

0

La façon la plus facile serait probaply être ceci:

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 

}