2

这是代码

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 查询?

请问有什么想法吗?

4

2 回答 2

3
$cond = $st ? "= '1'":" > '0'";
$sql = "SELECT username FROM users WHERE active_code $cond";
于 2013-05-20T05:14:16.060 回答
2

只需定义一个保持条件的变量:

if ($st) {
    $condition = "active_code = '1'";
} else {
    $condition = "active_code > '0'";
}

$sql = "SELECT username FROM users WHERE $cond";
于 2013-05-20T05:08:33.527 回答