开发者

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.....

There is a possibility that numResults could equal 0 but it still shou开发者_如何转开发ld not cause this.

Could it be the != in the first line that is causing it??


The problem is you have a bad SQL query:

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

Note the improper , after age = "$age" in the WHERE clause. 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; print mysql_error() when it's FALSE. 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.


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

There is a possibility that numResults could equal 0 but it still should not cause this.

No. It means you have a problem with your SQL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜