SQL LIMIT返回'零'-0-行(IN PHP) [英] SQL LIMIT return 'zero' - 0 - rows(IN PHP)

查看:159
本文介绍了SQL LIMIT返回'零'-0-行(IN PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当查询返回零行时,此查询中有错误.
错误编号:1064

I have an error in this query, when the query returns zero rows.
Error Number: 1064

您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第3行的"-20,20"附近使用

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 '-20,20' at line 3

选择玩家的pl.name,pl.email pl参加pl_id = pl_b.id_player的玩家pl_b在哪里pl_b.id_bonus = 3限制-20,20
我的方法是:

SELECT pl.name,pl.email FROM players pl JOIN players_bonus pl_b on pl.id = pl_b.id_player WHERE pl_b.id_bonus = 3 LIMIT -20,20
My method is:


    public function getPViews_num_rows($limit = array(0,20),$page_num = 1,$id) {
        $limit = "LIMIT {$limit[0]},{$limit[1]}";
    $sql = "SELECT pl.name,pl.email FROM players pl 
            JOIN players_bonus pl_b on pl.id = pl_b.id_player 
                WHERE pl_b.id_bonus = ? {$limit}";

    $where =  array($id);
    $query = $this->db->query ( $sql,$where );
    return $query->num_rows ();
}

在执行此查询之前,我不想执行其他查询以对行进行计数. 感谢您的回答.

I don't wanna do another query to count rows,before I do this query. Thanks for the answers.

推荐答案

您不能为LIMIT子句指定 值:

You can not specify negative value to LIMIT clause:

LIMIT -20,20 

这意味着您要从-20开始返回20行,这是 错误 .

It means you want to return 20 rows starting from -20 which is wrong.

这篇关于SQL LIMIT返回'零'-0-行(IN PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆