简体   繁体   English

mysql_num_rows的问题

[英]problems with mysql_num_rows

for some reason i can not understand im having troubles with mysql_num_rows. 由于某种原因,我无法理解我在使用mysql_num_rows遇到麻烦。

Heres the script: 这是脚本:

$notquery = 'SELECT * FROM notification WHERE uid = 1 AND read = 0 
AND tipo = post 
OR tipo = subpost OR tipo = logros';

$notQuery = (mysql_query($notquery));

$num_rows = mysql_num_rows($notQuery);

error: 错误:

Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource

This is probably because you have an error in the query execution. 这可能是因为查询执行中有错误。
Try adding or die(mysql_error()) to debug what's going wrong... 尝试添加or die(mysql_error())调试出了什么问题...

update the code to : 将代码更新为:
$notQuery = mysql_query($notquery) or die(mysql_error());

You input a string into mysql_num_rows =) 您在mysql_num_rows =中输入一个字符串

You use $notquery and $notQuery mixed... That must be the silliest thing I've ever seen. 您将$notquery$notQuery混合使用...那一定是我见过的最$notQuery的事情。

Try this: 尝试这个:

$sql = 'SELECT .....';
$result = mysql_query($sql);
echo mysql_error()."\n";
$numRows = mysql_num_rows($result);

Obviously, this might produce the same error, since you don't check for errors :) $result might not be a MySQL resource (it might be FALSE ). 显然,这可能会产生相同的错误,因为您没有检查错误:) $result可能不是MySQL资源(可能是FALSE )。

The sql is full with syntax error, try this sql充满语法错误,请尝试此

SELECT * FROM notification 
WHERE 
uid = 1 AND 
`read` = 0 AND 
tipo in('post', 'subpost', 'logros');

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM