the_garg Posted October 15, 2017 Report Share Posted October 15, 2017 (edited) Hola, resulta que quiero realizar una lista de usuarios multinivel, tengo una base de datos la cual tiene usuarios y sus referidos: usuario | correo | pass | referido user1 | [email protected] | 123 | user2 | [email protected] | 123 | user1 user3 | [email protected] | 123 | user1 user4 | [email protected] | 123 | user2 user5 | [email protected] | 123 | user3 user6 | [email protected] | 123 | user3 lo que hice es crear una funcion la cual añada los usuarios a un ARRAY en php ejemplo: Array ( [2] => Array ( [1] => Array ( [id] => 4 [usuario] => user4 [correo] => [email protected] [freg] => 1508010822 [cactiva] => 0 ) [2] => Array ( [id] => 5 [usuario] => user5 [correo] => [email protected] [freg] => 1508010822 [cactiva] => 0 ) [3] => Array ( [id] => 6 [usuario] => user6 [correo] => [email protected] [freg] => 1508010822 [cactiva] => 0 ) ) [1] => Array ( [1] => Array ( [id] => 2 [usuario] => user2 [correo] => [email protected] [freg] => 1507425300 [cactiva] => 0 ) [2] => Array ( [id] => 3 [usuario] => user3 [correo] => [email protected] [freg] => 1507965993 [cactiva] => 0 ) ) ) y resulta que el resultado no es el mismo si no que: Array ( [2] => Array ( [1] => Array ( [id] => 4 [usuario] => user4 [correo] => [email protected] [freg] => 1508010822 [cactiva] => 0 ) ) [1] => Array ( [1] => Array ( [id] => 2 [usuario] => user1 [correo] => [email protected] [freg] => 1507425300 [cactiva] => 0 ) [2] => Array ( [id] => 3 [usuario] => user2 [correo] => [email protected] [freg] => 1507965993 [cactiva] => 0 ) ) ) el codigo utilizado es el siguiente: function niveles($u_usuariox, $u_id, $y, $nivel, $niveles){ global $con; $nivel = $nivel+1; /*if($nivel <= $niveles){ for($x=1;$x<5;$x++){ $miarray[$x] = array(usuario => "user$u_usuario"); $array = niveles($usuario, $id,'', $nivel, $niveles); } $array[$nivel] = $miarray; $niveles_array = $array; return $array; }*/ if($nivel <= $niveles){ $query_mlmu = mysqli_query($con, "SELECT * FROM ref_usuarios WHERE referido='$u_usuariox'"); $query_mlmux = mysqli_query($con, "SELECT * FROM ref_usuarios WHERE referido='$u_usuariox'"); $x = 1; if(mysqli_fetch_array($query_mlmux)){ while($sql_mlmu=mysqli_fetch_array($query_mlmu)){ $id_user = $sql_mlmu['id']; $cactiva = $sql_mlmu['cactiva']; $freg = $sql_mlmu['freg']; $query_u = mysqli_query($con, "SELECT * FROM usuarios WHERE id='$id_user'"); $sql_u = mysqli_fetch_array($query_u); $us_id = $sql_u['id']; $us_usr = $sql_u['usuario']; $us_cor = $sql_u['correo']; if($y > 1){ $z = $y; }else{ $z = $x; } $miarray[$z] = array(id => $us_id, usuario => $us_usr, correo => $us_cor, freg => $freg, cactiva => $cactiva); $arrayx = niveles($us_usr, $us_id, $z, $nivel, $niveles); if($arrayx){ $array = $arrayx; } $x++; } $array[$nivel] = $miarray; return $array; } } } $niveles = niveles($u_usuario, $u_id, 1, '0', '5'); print_r($niveles); La idea es despues crear varios niveles, en este caso 5 niveles y la lista nivel1 tendra la lista de usuarios directos del user1, la lista nivel2 tendrá la lista de los ususarios user2 y user3, y asi progresivamente. no puedo hacerlo funcionar como quiero, he tratado de todo pero no se me ocurre más que hacer. alguna ayudita?? Edited October 15, 2017 by the_garg Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now