Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend 1.12中的复杂查询_Php_Mysql_Zend Framework - Fatal编程技术网

Php Zend 1.12中的复杂查询

Php Zend 1.12中的复杂查询,php,mysql,zend-framework,Php,Mysql,Zend Framework,我试图在Zend 1.12中获得与下面这个查询相同的结果 SELECT te.id_usuario, u.nome, te.id_texto, t.titulo FROM usuarios u, tex_turmas_alunos ta, tex_testes te, tex_textos t, publicacoes p WHERE te.id_usuario=u.id and u.id=ta.id_aluno and ta.id_turma=10

我试图在Zend 1.12中获得与下面这个查询相同的结果

    SELECT te.id_usuario, u.nome, te.id_texto, t.titulo 
    FROM usuarios u, tex_turmas_alunos ta, tex_testes te, tex_textos t, publicacoes p
    WHERE te.id_usuario=u.id 
        and u.id=ta.id_aluno and ta.id_turma=10
        and te.id_texto=t.id
        and te.acertou = 'sim'
        and ta.ativo='sim'
        and te.id_texto=p.id_texto and p.id_turma=ta.id_turma
    GROUP BY te.id_usuario, t.id
    ORDER BY u.nome, t.titulo
这是我的密码:

1:

2:

第一个查询的结果是:

    SELECT `u`.`nome`, `te`.`id_texto`, `te`.`id_usuario`, `t`.`titulo` FROM `usuarios` AS `u` INNER JOIN `tex_turmas_alunos` AS `ta` ON ta.ativo = 'sim' AND ta.id_aluno = u.id INNER JOIN `tex_testes` AS `te` ON te.acertou = 'sim' INNER JOIN `tex_textos` AS `t` ON te.id_texto = t.id INNER JOIN `publicacoes` AS `p` ON p.id_turma = ta.id_turma WHERE (ta.id_turma = '11') GROUP BY `te`.`id_usuario`, `t`.`id` ORDER BY `u`.`nome` ASC, `t`.`titulo` ASC
此结果与正确的返回值不符。我的问题出了什么问题

- 错误的结果如下:

nome                  id_texto id_usuario titulo
Another person          182      116       t2
Another person          183      18        t3
Another person          183      14        t3
Another person          183      24        t3
Another person          183      33        t3
Another person          183      19        t3
Another person          183      10        t3
我期望的结果是:

id_usuario     nome     id_texto     titulo
   108       Person 1      131       Text A
   108       Person 1      132       Text B
   108       Person 1      166       Text C
   108       Person 1      304       Text D
你明白其中的差别吗?这是两个完全不同的结果


谢谢

这是我的固定功能。效果很好

public function testesCorretos($id_turma){

        $sqlString = 
                "SELECT te.id_usuario,  u.nome, u.matricula, te.id_texto, t.titulo 
                FROM usuarios u, tex_turmas_alunos ta, tex_testes te, tex_textos t, publicacoes p
                WHERE te.id_usuario=u.id 
                  and u.id=ta.id_aluno 
                  and te.id_texto=t.id
                  and te.acertou = 'sim'
                  and ta.ativo='sim'
                  and te.id_texto=p.id_texto 
                  and p.id_turma=ta.id_turma
                  and ta.id_turma= ?
                GROUP BY te.id_usuario, t.id
                ORDER BY u.nome, t.titulo"; 

        $sql = $this->getAdapter()->query($sqlString, $id_turma);

        while($rows = $sql->fetchAll() ){           
            for($i =0; $i <= count($rows); $i++){
                $row[] =  array(
                        'id' => $rows[$i]['id_usuario'],
                        'nome' => $rows[$i]['nome'],
                        'matricula' =>  $rows[$i]['matricula'],
                        'id_texto' => $rows[$i]['id_texto'],
                        'titulo' => $rows[$i]['titulo']
                );
            }
        }

        return $row;

    }

您是否收到任何返回的错误?可能会激活它们?在第一个查询中,没有错误,但不会显示相同的结果。第二个错误是:PHP可捕获致命错误:Zend_Db_Statement_Pdo类的对象无法转换为Stringo。您可以提供第一个查询的结果和预期结果吗?这些查询不完全相同。有一次您使用“联接”联接表;还有一次你用where子句。它们不应该是相同的查询如何在FROM子句中使用多个表?我试过这样的方法:从数组'u'=>usuarios,ta=>tex\u turmas\u alunos。。。但是没有起作用
id_usuario     nome     id_texto     titulo
   108       Person 1      131       Text A
   108       Person 1      132       Text B
   108       Person 1      166       Text C
   108       Person 1      304       Text D
public function testesCorretos($id_turma){

        $sqlString = 
                "SELECT te.id_usuario,  u.nome, u.matricula, te.id_texto, t.titulo 
                FROM usuarios u, tex_turmas_alunos ta, tex_testes te, tex_textos t, publicacoes p
                WHERE te.id_usuario=u.id 
                  and u.id=ta.id_aluno 
                  and te.id_texto=t.id
                  and te.acertou = 'sim'
                  and ta.ativo='sim'
                  and te.id_texto=p.id_texto 
                  and p.id_turma=ta.id_turma
                  and ta.id_turma= ?
                GROUP BY te.id_usuario, t.id
                ORDER BY u.nome, t.titulo"; 

        $sql = $this->getAdapter()->query($sqlString, $id_turma);

        while($rows = $sql->fetchAll() ){           
            for($i =0; $i <= count($rows); $i++){
                $row[] =  array(
                        'id' => $rows[$i]['id_usuario'],
                        'nome' => $rows[$i]['nome'],
                        'matricula' =>  $rows[$i]['matricula'],
                        'id_texto' => $rows[$i]['id_texto'],
                        'titulo' => $rows[$i]['titulo']
                );
            }
        }

        return $row;

    }