Jump to content

Strange result in PDO::FETCH_ASSOC result


Recommended Posts

Captura de ecrã 2025-01-17 094327.png

Captura de ecrã 2025-01-17 094406.png

 

Hello

 

I'm having problems regardind the result of a query using PDO, my site have 2 different access, teacher and supervisor. Two supervisors have the same access but one show result and the other one no because of those "[]"

 $stmt = $DB_con->prepare("SELECT v.idVisita, 
                                                e.Escola, 
                                                p.Nome, 
                                                t.Turma,
                                                v.TipoTurma,
                                                v.Destino, 
                                                v.StartDate,
                                                v.EndDate, 
                                                v.TipoTransporte, 
                                                vt.alunosVisita, 
                                                vt.idTurma as idTurma, 
                                                v.TotalAluno,
                                                v.PdfVisita, 
                                                v.Avaliacao, 
                                                v.idProfessor, 
                                                v.Saida, 
                                                v.Chegada, 
                                                v.PlanoOcupacaoAlunos, 
                                                v.PlanoOcupacaoTurmas, 
                                                v.CustoEstadia, 
                                                v.CustoSeguro,
                                                v.CustoTransporte, 
                                                v.TipoSeguro, 
                                                v.TipoEstadia, 
                                                v.TipoTransporte, 
                                                v.idProfessor,
                                                v.Obs, 
                                                v.Areas, 
                                                v.Total,
                                                v.TipoEstadia, 
                                                v.TipoSeguro, 
                                                v.TipoTransporte, 
                                                v.Financiamento,
                                                vt.idTurma,
                                                v.PdfAvaliacao,
                                                v.Estado, 
                                                IF(v.Estado='1','DEF',IF(v.Estado='0','IND','AG')) as EstadoNum, 
                                                v.CustoIngressos, 
                                                v.TipoIngressos,
                                                v.haveClasses,
                                                d.Departamento,
                                                v.percent
                                                    FROM
                                                        visitas AS v
                                                        INNER JOIN escolas AS e ON (v.idEscola = e.idEscola)
                                                        INNER JOIN visitasturmas AS vt ON (v.idVisita = vt.idVisita)
                                                        INNER JOIN turmas AS t ON (vt.idTurma = t.idTurma)
                                                        INNER JOIN professores AS p ON (v.idProfessor = p.idProfessor)
                                                        INNER JOIN anosescolares AS ae ON (vt.idAnoEscolar = ae.idAnoEscolar)
                                                        INNER JOIN grupos g on p.idGrupo = g.idGrupo
                                                        INNER JOIN departamentos d on g.idDepartamento = d.idDepartamento
                                                        WHERE ae.Estado = 1 
                                                        ORDER BY v.idVisita,v.StartDate, t.Turma");
            $stmt->execute();
            $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
            echo json_encode($result);

Why?

How can i remove this?

 

 

Edited by gmc1103
Link to comment
https://forums.phpfreaks.com/topic/326556-strange-result-in-pdofetch_assoc-result/
Share on other sites

Just a thought here. Are the teachers and supervisors saved as an Array in the database? If they are, this could be the issue because PHP has issues displaying data to a certain user based on ID or username or whatever because it also retrieves the data from the database including the [""], for example, ["teacher"], ["supervisor"].

Just a thought.

Hello, thanks for participating

Are the teachers and supervisors saved as an Array in the database?

No

We have 4 supervisors, each one have same access rights and can see the same stuffs.

In this case, 2 supervisors who wants to check all study visits use this query. But as you can the final [] in one gives no data.

Edited by gmc1103
19 hours ago, requinix said:

That is not var_dump output.

What does this output:

$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);
var_dump(json_encode($result));

Hello agian

 

Sendin the file with 2 dumps

json_encode start at line 11579

The website don't allow me to put with code tags

But it seems it is the json_encode who is adding [] ate the end.

 

data.txt

Hello again 

 

Iv'e been checking php functions to check the result when i use this

 $result = $stmt->fetchAll(PDO::FETCH_ASSOC);

And one of function is sizeof

 $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
            //echo json_encode(getDadosVisita($result));
            echo sizeof($result);

For one supervisor the echo is 

154[]

And for another supervisor is

154

So now i'm lost...what's is going on to have [] in supervisor and none in another? 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.