douxia2053
2016-08-04 12:39
浏览 245
已采纳

SQL OFFSET语法错误

I'm trying to increase the offset every time by 3, so I used a variable that is increased by 3 every time a button is clicked (using ajax).

However, I keep getting a syntax error when using OFFSET.

Is this the correct way to do it?

$web = "SELECT * FROM `db` WHERE catid = 9 AND state = 1 ORDER BY ordering LIMIT 0,".$_POST['limit']." OFFSET ".$_POST['limit']."";

limit is increased by 3 every button click, if I leave out OFFSET, it works, but it keeps loading all items again, instead of just 3 new items.

My error:

There was an error running the query [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OFFSET 3' at line 1]

图片转代码服务由CSDN问答提供 功能建议

我每次都试图将偏移量增加3,所以我使用了一个每增加3的变量 单击一个按钮的时间(使用ajax)。

但是,使用 OFFSET 时,我不断收到语法错误。

这是正确的方法吗?

  $ web =“SELECT * FROM`db` WHERE catid = 9 AND state = 1 ORDER BY order LIMIT 0,”。  $ _POST ['limit']。“OFFSET”。$ _ POST ['limit']。“”; 
   
 
 

每按一次按钮,限制增加3,如果 我省略 OFFSET ,它可以工作,但它会继续加载所有项目,而不只是3个新项目。

我的错误:

运行查询时出错[您的SQL语法中有错误; 查看与MySQL服务器版本对应的手册,以便在第1行的'OFFSET 3'附近使用正确的语法。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douqi2804 2016-08-04 12:41
    已采纳

    The syntax should be:

     LIMIT ".$_POST['limit']." OFFSET ".$_POST['limit']."";
    

    The 0 conflicts with OFFSET.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongshuo2752 2016-08-04 12:41

    You look like your using both limit x,x and offset X in the same query.

    Try removing the offset part and just using limit X,x.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题