Codeigniter foreach不起作用

时间:2015-12-23 02:37:56

标签: php codeigniter

我有这个code.compiler没有输入foreach。我不知道为什么?虽然我写这个foreach在其他功能和工作,请任何人帮助我 在模型中

public function getting_profile_check($u)
{
    $this->db->where('login_name', $u);


    return $this->db->get('profile_check');

}

并在控制器中

public function get_profile_check($user)
{
    echo"i in get profile check";
    $d=$this->login_m->getting_profile_check($user);

    $data=array('check_res'=>$d,'first_time'=>"no");

    foreach($d->result() as $field)
        { 
        echo"i in for each in get";
          $image=$field->image_c;

          $view=$field->overview_c;
          $certi=$field->certi_c;
          $edu=$field->edu_c;
          $hopp=$field->hopp_c;
          $lang=$field->lang_c;
           echo"session".$image."   " .$edu;

        }


    }

3 个答案:

答案 0 :(得分:0)

试试这个

在控制器中

public function get_profile_check($user)
{
    echo"i in get profile check";
    $d = $this->login_m->getting_profile_check($user);

    $data=array('check_res'=>$d,'first_time'=>"no");

    foreach($d as $field)
    { 
        echo"i in for each in get";
        $image=$field->image_c;

        $view=$field->overview_c;
        $certi=$field->certi_c;
        $edu=$field->edu_c;
        $hopp=$field->hopp_c;
        $lang=$field->lang_c;
        echo"session".$image."   " .$edu;

    }
}

在模型中

public function getting_profile_check($u)
{
    $this->db->select("*");
    $this->db->where('login_name', $u);
    $query = $this->db->get('profile_check');
    $result = $query->result_array();
    return $result;
}

答案 1 :(得分:0)

在模特中做这样的事情:

public function getting_profile_check($u)
{

   $this->db->select('*')
            ->from('profile_check')
            ->where('login_name', $u);


   $query = $this->db->get();
   if($query->num_rows > 0){
       return $query->result_array();
    }

}
控制器中的

public function get_profile_check($user)
{
   echo"i in get profile check";

   $d=$this->login_m->getting_profile_check($user);


    foreach ($d as $row ) {

        echo $row['name_of_table_column'];
    }


}

答案 2 :(得分:0)

<强>模型

public function getting_profile_check($u)
{
   $this->db->where('login_name', $u);
   return $this->db->get('profile_check')->result();
}

<强>控制器

public function get_profile_check($user)
{
   echo"i in get profile check";
   $d=$this->login_m->getting_profile_check($user);

   foreach ($d as $row ) 
   {
        echo $row->name_of_table_column;
   }
}