错误查询SELECT SQL_CALC_FOUND_ROWS *来自用户WHERE gender ='$ gender'DESC limit 15

时间:2013-04-14 05:44:51

标签: mysql sql

帮帮我

错误讯息:

error query: "SELECT SQL_CALC_FOUND_ROWS * 
               FROM user WHERE gender='$gender'
               DESC limit 15";

2 个答案:

答案 0 :(得分:1)

问题在于这一行:

...WHERE gender='$gender' DESC limit 15

如您所见,您没有ORDER BY子句,但您使用了DESC个关键字。尝试通过删除关键字DESC

来修复它
...WHERE gender='$gender' limit 15

或添加ORDER BY子句

...WHERE gender='$gender' ORDER BY col_name DESC limit 15

答案 1 :(得分:1)

原则上,两个选项中的任何一个都应该有效:

SELECT SQL_CALC_FOUND_ROWS * FROM `user` WHERE `gender`='$gender' LIMIT 15;

或运行不带SQL_CALC_FOUND_ROWS的查询,并执行单独的SELECT COUNT(*)查询

SELECT * FROM `user` WHERE `gender`='$gender' LIMIT 10;
SELECT COUNT(*) FROM `user` WHERE `gender`='$gender';

PS:反击字段名称是一个好习惯。