简体   繁体   English

mysql_num_rows的问题

[英]problem with mysql_num_rows

Here is my code : 这是我的代码:

$sql1 = 'SELECT * FROM login WHERE age= "$age", town = "$town" and ID != "$id"';
$result1 = mysql_query($sql1);
$numResults1 = mysql_num_rows($result1);

My variables are fine, they have data in them. 我的变量很好,它们中有数据。 The error is this : 错误是这样的:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in..... 警告:mysql_num_rows():提供的参数不是.....中的有效MySQL结果资源。

There is a possibility that numResults could equal 0 but it still should not cause this. numResults可能等于0,但仍然不会导致这种情况。

Could it be the != in the first line that is causing it?? 可能是第一行中的!=引起了它?

The problem is you have a bad SQL query: 问题是您的SQL查询错误:

$sql1 = 'SELECT * FROM login WHERE age= "$age", town = "$town" and ID != "$id"';

Note the improper , after age = "$age" in the WHERE clause. 注意不当,以后age = "$age"WHERE子句。 It should be something like: 应该是这样的:

$sql1 = "SELECT * FROM login WHERE age= '$age' AND town = '$town' and ID != '$id'";

Your query has a syntax error. 您的查询语法错误。 Check $result1 before attempting to use it; 尝试使用$result1之前; print mysql_error() when it's FALSE . 当它为FALSE时打印mysql_error() You'll be told what the problem is. 系统将告诉您问题所在。

Also, your use of single quotes for the SQL query string means that variable interpolation will not occur... so you are unlikely to ever get rows returned. 同样,对SQL查询字符串使用单引号意味着不会进行变量插值...因此您不太可能返回行。

You're getting your single and double quotes mixed up. 您正在混合单引号和双引号。 Make all single quotes double quotes and vice versa. 使所有单引号双引号,反之亦然。

Try echoing $sql1 to see what I mean 尝试回显$sql1以了解我的意思

There is a possibility that numResults could equal 0 but it still should not cause this. numResults可能等于0,但仍然不会导致这种情况。

No. It means you have a problem with your SQL. 否。这意味着您的SQL有问题。

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

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