简体   繁体   English

修复错误:mysql_num_rows():提供的参数不是有效的MySQL结果资源

[英]Fixing the error: mysql_num_rows(): supplied argument is not a valid MySQL result resource

I'm not sure why this is not working: 我不确定为什么这不起作用:

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;
}

I have 2 different SQL statements and I just want to know if it will return a record or not. 我有2个不同的SQL语句,我只想知道它是否将返回记录。

You are not executing the query.check this manual for more details on mysql_num_rows() ,change your code like this 您没有执行查询。请查看本手册以获取有关mysql_num_rows()更多详细信息,像这样更改代码

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

Beware about mysql functions, they are insecure and deprecated. 当心mysql函数,它们是不安全的并且不建议使用。 Choose mysqli or pdo 选择mysqli或pdo

mysql_num_rows requires a resultset to be passed not a string variable. mysql_num_rows要求传递结果集而不是字符串变量。 Change to the following code: 更改为以下代码:

$result = mysql_query( $strSQL );
$strCaseExist = (mysql_num_rows($result) == 0) ? false : true;

您必须在检查num行之前执行查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mysql_num_rows():提供的参数不是有效的MySQL结果资源 - mysql_num_rows(): supplied argument is not a valid MySQL result resource mysql_num_rows():提供的参数不是有效的MySQL结果资源 - mysql_num_rows(): supplied argument is not a valid MySQL result resource 警告:mysql_num_rows():提供的参数不是没有mysql_error()的有效MySQL结果资源 - Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource with no mysql_error() 警告mysql_num_rows():提供的参数不是有效的MySQL结果 - Warning mysql_num_rows(): supplied argument is not a valid MySQL result 警告:mysql_num_rows():提供的参数不是有效的MySQL结果资源 - Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource 如何解决mysql_num_rows():提供的参数不是PHP中的有效MySQL结果资源 - How to solve mysql_num_rows(): supplied argument is not a valid MySQL result resource in php 警告:mysql_num_rows():提供的参数不是有效的MySQL结果资源 - Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource 警告:mysql_num_rows():提供的参数不是有效的MySQL结果资源nationalbuilder webhooks API - Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource nationbuilder webhooks API mysql_num_rows():提供的参数在15中不是有效的MySQL结果资源 - mysql_num_rows(): supplied argument is not a valid MySQL result resource in 15 mysql_num_rows():提供的参数不是有效的MySQL结果资源(唯一) - mysql_num_rows(): supplied argument is not a valid MySQL result resource (unique)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM