1
I’m 3 days trying to solve a problem, I can’t get multiple arrays with 1 single input and put and a single array.
EX:
Está imprimindo assim:
Array(
[0]=> "MT"
)
Array(
[0]=> "MG"
)
Array(
[0]=> "AM"
)
Quero fazer assim:
Array([0]=>"MT", [1]=>"MT", [2]=>"MT")
//MEU BANCO DE DADOS CONSIDERANDO APENAS AS PESSOAS DA REDE DO ID 1001
id_usuario | uf
-------------------------
1001 | SP
1003 | MG
1005 | AM
1027 | MT
// MONTAGEM DA REDE
1001
/ \
1003 1005
/
1027
My code:
<?php
function buscarEstados1($id){
include 'includes/conexao.php';
$s_down = "select id from tab_afiliado where upline = $id";
$res_down = $cnns->query($s_down);
foreach ($res_down as $down){
$aff_uf = $down['id'];//var_dump($aff_uf); //PEGA OS IDS 1003, 1027, 1005
$s_uf = "select uf,id_endereco from tab_endereco WHERE id_endereco = " . $aff_uf . "";
$res_uf = $cnns->query($s_uf);
foreach ($res_uf as $uf){
$arr = $uf['uf']; //var_dump($arr); //PEGA AS UF MG , AM , MT
}
buscarEstados1($aff_uf);
}
}
buscarEstados1(1001);
?>
I would like to take the Ufs and make an array only Array ( "MG" , "AM" , "MT");
The problem is as if the loop caught like this.
print_r(#arr);
$arr = array( "MG" );
$arr = array( "MT" );
$arr = array( "AM" );
try to fix this when mounting the array. If it is not feasible you will have to do a basic POG. (Gambiarra Oriented Programming)
– Daniel Omine
These values come from where of the bank? it is not very clear what is the problem.
– rray
Pq the function is called (end of the first foreach) and returned nothing?
– rray
include should not be within a recursive function, put it at the beginning of the file will avoid many headaches. php connection.
– Pedro Erick
This result happens pq 1 -
$arr
has its superscript value every turn of the foreach, 2 - the function does not return value and is called again.– rray
You can mark the answer that most helped you to solve the problem (Guilherme Lautert) as accepted, it gets a green light, or create your own response and explain the details. See => http://meta.pt.stackoverflow.com/a/1079/91
– rray