开发者

MYSQL: select row where field is smaller than other

this is my mysql query in php:

mysql_query("SELECT * FROM tbl WHERE logins < limit")

the mysql_affected_rows() returns -1. why this simple query doesnt work? field and table names are correct i've doubl开发者_运维技巧e checked


Try quoting your column names with backticks:

 mysql_query("SELECT * FROM tbl WHERE `logins` < `limit`")

You've got a column name same as a reserved MySQL keyword (limit).


You can't use mysql_affected_rows for SELECT queries, as per the PHP Manual:

mysql_affected_rows

Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query

Use mysql_num_rows instead.

Also, as p.campbell pointed out, don't forget to backquote the name of your 'limit' column, since you use a reserved work as the column name.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜