0
I am making a 4x4 matrix system for a client and I am having a difficulty in the following question: The system has to check if the indicated to be checked already has 4 people in the network, if there is then search in the next indicated to the side, until the end. If there is no return a message talking that has a vacancy available.
See the photo: http://i.imgur.com/hfLU8bp.png
The system checks at level 1: As seen in the photo has 4 The system then checks on the first user (Bruno) if below it (level 2) has 4, if it has not returned a message talking that has vacancy. In the photo has 4 below Bruno, then it would be right for him to check in João Vitor (on the side), but instead the system looks below Julia which is indicated by Bruno.
I have the code
public function QuantidadeLinhasMatriz($id, $nivel = 1){
$this->db->where('id_patrocinador', $id);
$patrocinadores = $this->db->get('patrocinadores');
if($patrocinadores->num_rows() >= 4){
foreach($patrocinadores->result() as $row){
echo $this->QuantidadeLinhasMatriz($row->id_usuario, $nivel+1).'<br />';
}
}else{
return 'Nivel '.$nivel.' disponivel na ID '.$id;
}
}
As can be seen on the top left side of the print, it is printed:
Nivel 3 disponivel na ID 9
Nivel 3 disponivel na ID 10
Nivel 3 disponivel na ID 11
Nivel 3 disponivel na ID 12
Nivel 2 disponivel na ID 7
Nivel 2 disponivel na ID 8
Nivel 2 disponivel na ID 17
The script until it is running correctly, but it is already checking the third level (without finishing checking the entire second level) and what it needed to return me was Nivel 2 disponivel na ID 7
In short: He has to check at the current level if in one of the members who are at that level there are 4 people, if there are, go to the next member, until the end. If all return that has 4 or more, then descend one more level and do the same check.
Are you selecting the 2 level of the same user? why when you enter the loop of a user who already has four below it this code is going to the first of these 4 below Bruno
– Wellington Silva Ribeiro