我有如下查询:
mssql_query("SELECT COUNT(*) FROM PRTL_PasswordSecurityQuestions where isPublished = 1 ")
当count大于3时,我需要显示一些内容。为此我已经把这样的语句放了。
if(mssql_query("SELECT COUNT(*) FROM PRTL_PasswordSecurityQuestions where isPublished = 1 ")>=3)
{......}
这是检查的正确方法。不管它不适合我。
答案 0 :(得分:4)
您无法在if条件中直接比较它:
if(mssql_query("SELECT COUNT(*) FROM PRTL_PasswordSecurityQuestions where isPublished = 1 ")>=3)
{......}
由于它返回结果集,您需要先获取它,在获取计数并存储之后,然后进行比较:
$query = mssql_query("SELECT COUNT(*) AS total FROM PRTL_PasswordSecurityQuestions WHERE isPublished = 1";
$row = mssql_fetch_assoc($query); // fetch it first
if($row['total'] > 3) {
// do what you have to do
}