-2
I have a function, and it checks if the ID that I’ve informed has more than six records in the database. If it has, then it takes, makes a select to return these 6 records and plays in an array and executes the same function, ie recursive function. If you have less than 6 records, then the system returns that same informed ID.
The problem is this, when I give "Return" he shows me "null" and when I use "echo" in place of "Return" it returns me the ID as should be the functioning of the code.
I’m calling first like this: $IDPatrocinador = $this->usuario_model->EscolhePatrocinadorRede(array(55))
I don’t want to return everyone who is less than 6... When I call function for the first time, pass 1 ID only, then if it is less than 6 returns only it. But if you have 6 or more, then I put them all in an array to do the same check. If in the first contents of the array return less than 6 so you don’t need to check the rest of the content array. Actually I only need the first 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);
}
}
because uses Return if echo that works????
– Sampaio Leal
put it like this
echo $this->usuario_model->EscolhePatrocinadorRede(array(55));
– Daniel Omine
This method is inside a controller in Codeigniter???
– novic
@Not virgilionovic, it’s inside a model
– Alisson Acioli