我想为我在companyProfileDetails()
中获得的其他功能提供公司 ID
我在控制器中的代码是:
public function company_profile()
{
$data['compData'] = $this->company_model->companyProfileDetails($this->session->userdata('peo_id'));
$data['compAgentData'] = $this->company_model->companyAgentDetails($compData->cmp_id);
$this->load->view('company_profile',$data);
}
我在模型中的代码:
public function companyProfileDetails($peo_id)
{
$sql = "SELECT * FROM company left join people_company on people_company.pcy_company_id = company.cmp_id where people_company.pcy_people_id ='".$peo_id."'";
$query = $this->db->query($sql);
return $query->row();
}
public function companyAgentDetails($cmp_id)
{
$sql = "SELECT peo_id,peo_name FROM people_company left join people on people.peo_id = people_company.pcy_people_id WHERE people_company.pcy_company_id ='23' ";
$query = $this->db->query($sql);
return $query->result();
}
像这样尝试。
public function company_profile()
{
$data['compData'] = $this->company_model->companyProfileDetails($this->session->userdata('peo_id'));
$data['compAgentData'] = $this->company_model->companyAgentDetails($data['compData']->cmp_id);
$this->load->view('company_profile',$data);
}
或
public function company_profile()
{
$compData = $this->company_model->companyProfileDetails($this->session->userdata('peo_id'));//Get row data
$id = $compData->cmp_id;//get row's id
$data['compAgentData'] = $this->company_model->companyAgentDetails($id);
$data['compData'] = $compData;
$this->load->view('company_profile',$data);
}