dongxizhe9755
2014-11-25 10:05
浏览 292
已采纳

SELECT ... LIMIT 0,1语法错误

    for($nr = 0; $nr < 2; $nr++){

        print $nr; print(gettype($nr));   // prints 0integer 

        $result = mysqli_query($con,"SELECT * FROM phcdl_files 
        ORDER BY file_id DESC LIMIT '$nr',1") 
        or die(mysqli_error($con));
    }

Trying to run the query above but I'm having troubles because of syntax. Running it on PhpMyAdmin with Limit 0,1 works good however

Any idea what's the problem?

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

  for($ nr = 0; $ nr&lt; 2; $ nr ++){
 
 打印$ nr; 打印(将gettype($ NR));  //打印0integer 
 
 $ result = mysqli_query($ con,“SELECT * FROM phcdl_files 
 ORDER BY file_id DESC LIMIT'$ nr',1”)
或者死(mysqli_error($ con)); 
  } 
   
 
 

尝试运行上面的查询,但由于语法问题,我遇到了麻烦。 在PhpMyAdmin上使用Limit 0,1运行它很好但是

知道问题是什么吗?

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

3条回答 默认 最新

  • dqb77047 2014-11-25 10:07
    已采纳

    Try with -

    "SELECT * FROM phcdl_files ORDER BY file_id DESC LIMIT $nr,1"
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doudun8705 2014-11-25 10:07

    I think the issue is that you're adding quote around the 0.

    Your SQL query should look like:

    "SELECT * FROM phcdl_files ORDER BY file_id DESC LIMIT $nr, 1"
    
    评论
    解决 无用
    打赏 举报
  • duanbage2161 2014-11-25 11:38

    remove single quotation of $nr veriable from query

    QUERY = "select * from tb_name order by id desc limit $nr , 1"
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题