[英]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.