douliang6563 2015-09-16 17:38
浏览 27

CakePHP查询参数OFFSET?

I'm trying create a SELECT to return some values. I want return these values paginated with LIMIT and OFFSET. To do it I'm trying create a query but doesn't works and throws a syntax exception of mysql.

How could I do it ?

public function findTarefas(){
            $this->autoRender = false;            
            $json = $this->request->input("json_decode", true);
            $id = $json["Pessoa"]["id"];
            $offset = $json["Pessoa"]["offset"];

            $tarefas = $this->Tarefa->query("SELECT * FROM responsavel_alunos RespAlunos "
                    . "INNER JOIN pessoas Responsavel ON (RespAlunos.pessoas_id = Responsavel.id) "
                    . "INNER JOIN pessoas Aluno ON (RespAlunos.pessoas_id1 = Aluno.id) "
                    . "INNER JOIN matriculas Matricula ON (Matricula.pessoas_id = Aluno.id) "
                    . "INNER JOIN turmas Turma ON (Matricula.turmas_id = Turma.id) "
                    . "INNER JOIN tarefas Tarefa ON (Tarefa.turmas_id = Turma.id) "
                    . "INNER JOIN disciplinas Disciplina ON (Tarefa.disciplinas_id = Disciplina.id) "
                    . "INNER JOIN pessoas Professor ON (Tarefa.pessoas_id = Professor.id) "
                    . "WHERE (Responsavel.id = ?) ORDER BY Tarefa.created DESC LIMIT 5 OFFSET ? ",
                    array($id, $offset)                    
                    );            

            $array;       
            if($tarefas){
                $array = array("status"=>"1", "result"=>$tarefas);
            }else{
                $array = array("status"=>"0", "result"=>$tarefas);
            }

            return json_encode($array);
        }

Exception

{
    "code": 500,
    "name": "SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''0'' at line 1",
    "message": "SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''0'' at line 1",
    "url": "/PainelEscolar/Tarefas/findTarefas.json",
    "error":
    {
        "errorInfo":
        [
            "42000",
            1064,
            "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 ''0'' at line 1"
        ],
        "queryString": "SELECT * FROM responsavel_alunos RespAlunos INNER JOIN pessoas Responsavel ON (RespAlunos.pessoas_id = Responsavel.id) INNER JOIN pessoas Aluno ON (RespAlunos.pessoas_id1 = Aluno.id) INNER JOIN matriculas Matricula ON (Matricula.pessoas_id = Aluno.id) INNER JOIN turmas Turma ON (Matricula.turmas_id = Turma.id) INNER JOIN tarefas Tarefa ON (Tarefa.turmas_id = Turma.id) INNER JOIN disciplinas Disciplina ON (Tarefa.disciplinas_id = Disciplina.id) INNER JOIN pessoas Professor ON (Tarefa.pessoas_id = Professor.id) WHERE (Responsavel.id = ?) ORDER BY Tarefa.created DESC LIMIT 5 OFFSET ?"
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
    • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
    • ¥15 知识蒸馏实战博客问题
    • ¥15 用PLC设计纸袋糊底机送料系统
    • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
    • ¥15 用C语言输入方程怎么
    • ¥15 网站显示不安全连接问题
    • ¥15 51单片机显示器问题
    • ¥20 关于#qt#的问题:Qt代码的移植问题
    • ¥50 求图像处理的matlab方案