有没有办法让我不必在每个条件下编写完整查询?if($_GET['l'] == 1){ $num = $db -> query("SELECT * FROM text WHERE type = '' AND gg = '1'") -> num_rows;} elseif($_GET['l'] == 2){ $num = $db -> query("SELECT * FROM text WHERE type = '' AND gg = '2'") -> num_rows;} else { $num = $db -> query("SELECT * FROM text WHERE type = ''") -> num_rows;}
1 回答
凤凰求蛊
TA贡献1825条经验 获得超4个赞
很简单,声明一个变量并在变量中进行查询。
$query = "SELECT * FROM text WHERE type = ''";
if($_GET['l'] == 1){
$query .= " AND gg = '1'";
}
elseif($_GET['l'] == 2){
$query .= " AND gg = '2'";
}
else {
$query .= " ";
}
$num = $db -> query($query) -> num_rows;
希望这对你有帮助。
- 1 回答
- 0 关注
- 71 浏览
添加回答
举报
0/150
提交
取消