PHP MySQL查询可能包含数据(如果存在)

时间:2013-10-25 08:35:07

标签: php mysql

我当前的查询字符串是

    $var = '  fkMemberId = \'24\' AND month(DisallowTimeFrom) = \'10\' ';

毋庸置疑,如果表中没有十月,那么我得到一个空的结果。

我想要实现的目标是......

    $var = ' fkMemberId = \'24\' BUT MAY ALSO CONTAIN BUT IF NULL CONTINUE QUERY month(DisallowTimeFrom) = \'10\' ';

fkMemberId = \ '24 \'必须

月(DisallowTimeFrom)= \''\'\ n \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n <

为了简洁,我遗漏了其余的查询。

1 个答案:

答案 0 :(得分:0)

$var = ' fkMemberId = \'24\' AND (DisallowTimeFrom IS NULL OR month(DisallowTimeFrom) = \'10\') ';