Answers
直接上代码:
$query = [];
$valid = ['type', 'area', 'year', 'person']; // 有效的查询Key:类型/地区/年代/明星
foreach($_GET AS $queryName) {
// 查询全部时,直接忽略该条件
if( ($_GET[$queryName] !== 'all') && in_array($queryName, $valid) ) {
$query[$queryName] = $_GET[$queryName];
}
}
$where = count($query) ? 'WHERE '.implode(',', $query) : '';
$result = $db->query("SELECT * FROM tableName {$where}");
乡村余文乐
answered 9 years, 9 months ago