I have a function and it checks if the given ID has more than 6 records in the database. If it does, then it picks up, makes a select to return those 6 records and plays in an array and performs the same function, that is, recursive function. If you have less than 6 records, then the system returns this same ID.
The problem is this, when I give return it shows me " null" and when I use echo instead of "return" It returns me the ID how the code should work.
I'm calling this first: $IDPatrocinador = $this->usuario_model->EscolhePatrocinadorRede(array(55))
I do not want to return everyone who is less than 6 ... When I call for the first time, it passes 1 ID only, so if it is less than 6 returns only her. But if I have 6 or more then I put all of them in an array to do the same verification. If in the first array contents return less than 6 so you do not need to check the rest of the content of the array. I actually need only the first one to give less than 6.
public function EscolhePatrocinadorRede($id_patrocinador){
if(!empty($id_patrocinador)){
foreach($id_patrocinador as $IDPatrocinador){
$this->db->where('id_patrocinador', $IDPatrocinador);
$patrocinadores = $this->db->get('patrocinadores');
if($patrocinadores->num_rows() < 3){
return $IDPatrocinador;
}
}
$idUsuario = array();
foreach($id_patrocinador as $IDPatrocinador){
$this->db->order_by('id_usuario', 'ASC');
$this->db->where('id_patrocinador', $IDPatrocinador);
$patrocinadores = $this->db->get('patrocinadores');
foreach($patrocinadores->result() as $patrocinador){
$idUsuario[] = $patrocinador->id_usuario;
}
}
$this->EscolhePatrocinadorRede($idUsuario);
}
}