php - 修复错误 : mysql_num_rows(): supplied argument is not a valid MySQL result resource

标签 php mysql

我不确定为什么这不起作用:

if($strFilterByStatus != 'all' &&  $strFilterByYear == 'all' && $strFilterByMonth !='all')
{
    $strSQL = "SELECT * FROM tblcase where recovered = '".$strFilterByStatus."' and monthreported = '".$strFilterByMonth."'" ;
}
else if($strFilterByStatus != 'all' &&  $strFilterByYear != 'all' && $strFilterByMonth !='all')
{
    $strSQL = "SELECT * FROM tblcase where recovered = '".$strFilterByStatus."' and yearreported = '".$strFilterByYear."' and monthreported = '".$strFilterByMonth."'" ;
}


if (mysql_num_rows($strSQL)==0)
{
    $strCaseExist = false;
}
else
{
    $SQL=mysql_query($strSQL);  
    $strCaseExist = true;
}

我有 2 个不同的 SQL 语句,我只想知道它是否会返回一条记录。

最佳答案

您没有执行查询。检查此 manual有关 mysql_num_rows() 的更多详细信息,请像这样更改您的代码

$resrce =mysql_query($strSQL)
if (mysql_num_rows($resrce)==0)

注意 mysql 函数,它们不安全且已弃用。选择mysqli或者pdo

关于php - 修复错误 : mysql_num_rows(): supplied argument is not a valid MySQL result resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22271935/

相关文章:

mysql - CakePHP 迁移插件工作流程

php - Laravel 响应发送 android APK 文件

mysql - 插入 ID 号而不是使用 Enum 类型 - 查询会变慢多少?

php - 拉拉维尔 5.2 : Order Models by Pivot table field

php - WordPress 重定向到静态index.html 页面,同时保持子页面完整?

python - sqlalchemy func.group_concat 和数据的随机顺序

php - CodeIgniter:连接两个mysql实例

php - 比较简单的 Preg_match_all 导致 502 Bad Gateway

php - 在不引用 Closure 内部类的情况下测试 PHP Closure

javascript - 按钮不调用脚本 - onclick 方法