mysqli按参数筛选显示所有选项

时间:2015-11-27 01:27:14

标签: sql mysqli show records

如果参数与showall匹配,修改此查询以显示所有记录的最佳方法是什么,这是正常的做法:

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

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

1 个答案:

答案 0 :(得分:0)

最容易的方法是:

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

}