这是代码
if ($st) active_code = '1';
if (!$st) active_code > '0';
SELECT username FROM users WHERE active_code = '1'
SELECT username FROM users WHERE active_code > '0'
有没有办法进行然后一个 sql 查询?
请问有什么想法吗?
$cond = $st ? "= '1'":" > '0'";
$sql = "SELECT username FROM users WHERE active_code $cond";
只需定义一个保持条件的变量:
if ($st) {
$condition = "active_code = '1'";
} else {
$condition = "active_code > '0'";
}
$sql = "SELECT username FROM users WHERE $cond";