2
I need a multidimensional array that will be composed of database information, but I’m not able to add this information. I can’t explain it very well, so I’ll show you.
So I want to:
Array
(
[0] => Array
(
[valor_apostado] => 100
[valor_final] => 817
[id_aposta] => 1022
[0] => Array
(
[timeApostado] => Motherwell
[partidaApostada] => Motherwell x Hearts
)
[1] => Array
(
[timeApostado] => Hearts
[partidaApostada] => Pandora x Hearts
)
)
)
But he comes like this:
Array
(
[0] => Array
(
[valor_apostado] => 100
[valor_final] => 817
[id_aposta] => 1022
[0] => Array
(
[timeApostado] => Motherwell
[partidaApostada] => Motherwell x Hearts
)
)
The other part of the array within the array is not displayed.
My code:
$idAnt = 0;
$array = "";
$i = 0;
$n = 0;
while($dado = $pegar->fetch(PDO::FETCH_ASSOC)) {
$valor_apostado = $dado["valor_apostado"];
$valor_final = $dado["valor_final"];
$tipo_aposta = $dado["tipo_aposta"];
$time = $dado["nome_time"];
$idAposta = $dado["id_aposta"];
if($idAposta == $idAnt) {
$x[$n] = array(
"timeApostado" => $tipo_aposta,
"partidaApostada" => $time
);
$n++;
} else {
$n = 0;
$x = array(
"valor_apostado" => $valor_apostado,
"valor_final" =>$valor_final,
"id_aposta" => $idAposta,
$n => array(
"timeApostado" => $tipo_aposta,
"partidaApostada" => $time
)
);
$array[$i]= $x;
$i++;
$n++;
}
$idAnt = $idAposta;
}
When you do the database search, is all the information brought in? If yes, try to do this:
$x[$n][]
– Not The Real Hemingway
Yes, all at once. I’ll try!
– Krint