返回停止循环迭代


Return stops loop iteraction

>我有一个函数,它返回所有用户的朋友,但只返回一行而不是与查询关联的所有行。

 function getAllFriends($email){
             $myid = $this->getStudentId($email);
             $this->db->where('aluno_id',$myid);
             $sql =  $this->db->get('mutamba_amigos');
             if($sql->num_rows() > 0){
                 foreach ($sql->result() as $r){
                     $this->db->where('id',$r->amizade_id);
                     $sql2 =  $this->db->get('mutamba_amizades');
                     if($sql2->num_rows() > 0){
                            foreach ($sql2->result() as $f){
                                $this->db->where('id',$f->aluno_id);
                                $sql3 = $this->db->get('alunos');
                                if ($sql3->num_rows() > 0) {
                                   // echo "<br> Model rows: ". $sql3->num_rows();
                                    return $sql3->result();
                                }else{
                                      return false;
                                }
                             } 
                        }
                 }

             }else{
                // echo 'nothing found';
                return false;
             }

         }

如果我评论return $sql3->result();' and uncomment the回显"
模型行:"。$sql 3->num_rows();the count is right. I know it must be the返回"停止循环迭代。我该如何解决这个问题?

请提供任何帮助,将非常出色。

是的,我创建了一个数组"friends",而不是返回我使用$sql3的结果array_push($friends,$sql3->result())然后在循环块之后返回"friends"数组。如果有更直接的方法,请告诉我。我对 mysql 和 php 有点生疏,所以,希望其他解决方案。谢谢。