-2
I am not being able to access the indexes of an array, which is the result of a query, through the column name, only by the corresponding numbers.
<?php
$conexao = mysqli_connect("localhost", "root", "", "bdteste");
function verificaVencidos($conexao){
$query = "select * from tbl_atividades where atualizado <> 'S'";
$resultado = mysqli_query($conexao, $query);
$lista_resultado = array();
while($pre_lista = mysqli_fetch_array($resultado)){
array_push($lista_resultado, $pre_lista);
}
return $lista_resultado;
}
$resultados = verificaVencidos($conexao);
foreach($resultados as $print){
echo $print[1] . "<BR>";
echo $print[2] . "<BR>";
echo $print[3] . "<BR>";
echo $print[4] . "<BR>";
echo $print[5] . "<BR>";
echo $print[6] . "<BR>";
echo $print[7] . "<BR>";
echo $print[8] . "<BR>";
echo $print[9] . "<BR>";
echo $print[10] . "<BR>";
echo $print[11] . "<BR>";
echo $print[12] . "<BR>";
}
wish to access in this way:
<?php
$conexao = mysqli_connect("localhost", "root", "", "bdteste");
function verificaVencidos($conexao){
$query = "select * from tbl_atividades where atualizado <> 'S'";
$resultado = mysqli_query($conexao, $query);
$lista_resultado = array();
while($pre_lista = mysqli_fetch_array($resultado)){
array_push($lista_resultado, $pre_lista);
}
return $lista_resultado;
}
$resultados = verificaVencidos($conexao);
foreach($resultados as $print){
echo $print['tipo_atividade'] . "<BR>";
}
but when I put it like this returns the following error:
Notice: Undefined index: tipo_atividade in
C:\xampp\htdocs\atualizador\atualizador-beta.php on line 23
Already I stopped other topics with similar subject, but none gave solution.
print_r result:
Array ( [0] => 93233 [c digo] => 93233 [1] => 696 [COD] => 696 [2] => 3 FG ADMINISTRA O (CORDEIRO) [EMPRESAS] => 3 FG ADMINISTRA O (CORDEIRO) [3] => PRESUMIDO [TRIBUTACAO] => PRESUMIDO [4] => PEDRO [RESPONSAVEL] => PEDRO [5] => GLEISI. R [DESIGNATOR] => GLEISI. R [6] => DCTF [TIPO_ATIVIDADE] => DCTF [7] => [DT_INICIO] => [8] => 2019-09-24 00:00:00 [DT_VENCIMENTO] => 2019-09-24 00:00:00 [9] => [DT_FIM] => [10] => PENDING [STATUS] => PENDING [11] => [DETAILS] => [12] => [FEEDBACK] => [13] => ACCOUNTING [DEPARTMENT] => ACCOUNTING [14] => MATRIX [EMPRESA_ORIGEM] => MATRIX [15] => [DATA_VISUALIZADO] => [16] => [DATA_FEEDBACK] => [17] => S [ARCHIVE] => S [18] => [DIRECTORY] => [19] => C [EXTRA_URGENTE_COMUM] => C [20] => N [VIEWED] => N [UPDATED] => N [22] => [DATA_DETALHES] => [23] => TO CHECK OUT [CONFERENCIA] => A CONFERIR [24] => [CONFERENTE] => [25] => 1 [QNTD_PROCESSOS] => 1 [26] => [EXTRA_VISUALIZADO] => [27] => [FEDBACK_VISUALIZADO] => [28] => [URGENTE_VISUALIZADO] => [29] => [OBSERVACOES_PRIVADAS] => [30] => N [DETALHE_VISALIALIZADO] => N [31] => N [OBSERVACOES_PRIVADAS_VISUALIZADAS] => )
And there’s the column
tipo_atividade
in the database? What is the result ofprint_r($print)
?– Woss
Hello! I believe you have to use
aspas duplas
, I checked in the official PHP documentation for the function mysqli_fetch_array and there presents the use ofaspas dupla
. Below is the documentation link PHP Doc– Nicolas Pereira
Yes @Andersoncarloswoss just checked this my error, I haven’t looked at the code undo! already delete my comment.
– Nicolas Pereira
@Andersoncarloswoss does exist, I can access it so if in select I instead of putting "select * from" put select type_activity from". The result of the print_r is all query data: Array ( [0] => 93233 [c digo] => 93233 [1] => 696 [COD] => 696 [2] => 3 FG ADMINISTRA O (CORDEIRO) [EMPRESAS] => 3....
– Denied
@Even Nicolaspereira with double quotes won’t go. It will only, as I said, if I put "select tipo_activity from" instead of "select * from", but I need to get all the fields in the query.
– Denied
@Denied Can put this output from the
print_r
in the question?– Woss
@Denied you running the
SELECT * FROM
and when printing the variable you put the index of it, right? example, run theSELECT * FROM
and in theecho
leave as follows:echo $print[indexDoCampo]."<br>";
– Nicolas Pereira
@Nicolaspereira you say that way? echo $print[1] ? if yes, so it goes.
– Denied
Are you sure the column name is all tiny anyway? Wouldn’t it be
TIPO_ATIVIDADE
?– Woss
I believe the @Andersoncarloswoss solution will work, I believe the field in the database is
TIPO_ATIVIDADE
– Nicolas Pereira
@Andersoncarloswoss guy, that’s right. I’m familiar with VBA that the query is not case sensitive, and also accessed by the index of the array. Thank you very much for your answers!
– Denied