如何使用codeigniter获取和显示数组值?

时间:2016-02-07 09:06:33

标签: php function codeigniter model-view-controller view

如何使用codeigniter获取和显示数组值。我已在视图页面中添加但未获取输出。让我知道如何调用函数以及值并再次显示结果以查看页面

Controller.page
----------------
public function abc($id,$company)
{
$result_array['memberTo'] =$this->Admin_model->Abc($id,$company);
$this->load->view('admin_dashboard',$result_array);
}

View.page
----------------
$CI =& get_instance();             
$CI->abc($name_mem,$company);  
echo $memberTo[0]->name; 

model.page
----------------
public function Abc($id,$company){

  // echo $db_name = $company."_db"; 

  $this->dbm = $this->load->database('$db_name', true);
  $this->db->where('folio', $id);
        $result = $this->db->get('members');
        $data = array();
        foreach($result->result() as $row) {
            $data[] = $row;
        }
        return $data;

    }

1 个答案:

答案 0 :(得分:0)

您可以更改模型功能和查看页面

试试这样 型号页面

public function Abc($id,$company){
// echo $db_name = $company."_db"; 
 $this->dbm = $this->load->database('$db_name', true);


$this->db->where('folio', $id);
    $result = $this->db->get('members');
    $data = array();

    return $result;

}

在您的视图页面

$CI =& get_instance();             
$CI->abc($name_mem,$company);  
foreach($memberTo->result() as $row)
{
echo $row->name; 
}