gmc1103 Posted Friday at 09:48 AM Share Posted Friday at 09:48 AM (edited) 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 Friday at 09:52 AM by gmc1103 Quote Link to comment https://forums.phpfreaks.com/topic/326556-strange-result-in-pdofetch_assoc-result/ Share on other sites More sharing options...
requinix Posted Friday at 04:49 PM Share Posted Friday at 04:49 PM What does var_dump($result) show? Quote Link to comment https://forums.phpfreaks.com/topic/326556-strange-result-in-pdofetch_assoc-result/#findComment-1648130 Share on other sites More sharing options...
gmc1103 Posted Saturday at 09:51 PM Author Share Posted Saturday at 09:51 PM Hello, thanks for your answer. The var_dump shows [] at the end in one supervisor and without [] in another one supervisor...i don't see why. The images posted are the var_dump result. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/326556-strange-result-in-pdofetch_assoc-result/#findComment-1648199 Share on other sites More sharing options...
requinix Posted Saturday at 11:28 PM Share Posted Saturday at 11:28 PM 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)); Quote Link to comment https://forums.phpfreaks.com/topic/326556-strange-result-in-pdofetch_assoc-result/#findComment-1648200 Share on other sites More sharing options...
Moorcam Posted Sunday at 03:50 AM Share Posted Sunday at 03:50 AM 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. Quote Link to comment https://forums.phpfreaks.com/topic/326556-strange-result-in-pdofetch_assoc-result/#findComment-1648207 Share on other sites More sharing options...
gmc1103 Posted Sunday at 06:25 PM Author Share Posted Sunday at 06:25 PM (edited) 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 Sunday at 06:27 PM by gmc1103 Quote Link to comment https://forums.phpfreaks.com/topic/326556-strange-result-in-pdofetch_assoc-result/#findComment-1648237 Share on other sites More sharing options...
gmc1103 Posted Sunday at 07:09 PM Author Share Posted Sunday at 07:09 PM 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 Quote Link to comment https://forums.phpfreaks.com/topic/326556-strange-result-in-pdofetch_assoc-result/#findComment-1648240 Share on other sites More sharing options...
gmc1103 Posted Sunday at 10:11 PM Author Share Posted Sunday at 10:11 PM 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? Quote Link to comment https://forums.phpfreaks.com/topic/326556-strange-result-in-pdofetch_assoc-result/#findComment-1648248 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.