I am trying to get data from my database , based on the company_name but getting error:
Error:Object of class stdClass could not be converted to string
staff controller :
function index()
{
$user_id = $this->session->userdata('manager');
// echo "index"; die;
$company_name = $this->staff_model->getCompanyName($user_id);
// print_r($company_name);
// die;
$data['staff'] = $this->staff_model->getStaffDetails($company_name); //Error on this line
// print_r($data);
// die;
$this->load->view('manager/staff/index',$data);
}
staff_model
<?php
class Staff_model extends CI_Model
{
//table name: user_login
function getCompanyName($user_id)
{
$company_name=$this->db->select('company_name')->from('user_login')->where(array('id' => $user_id,'delete_flag'=>0))->get()->row();
return $company_name;
}
function getStaffDetails($company_name)
{
$delete_flag=0;
return $this->db->get_where('user_login',array('delete_flag!='=>$delete_flag , 'company_name'=>$company_name))->result(); //Error on this line
// $query = $this->db->select('*')
// ->from('user_login')
// ->where("(delete_flag = '$delete_flag )")
// ->where("(company_name = $company_name)"); //Error on this line
// return $query(); }
And running
print_r($company_name);
die;
results:
stdClass Object ( [company_name] => ASGB )
Would appreciate if anyone can help.
company_nameproperty of$company_name? yourgetCompanyNamemethod returns an object, not a string for a name$data['staff'];??$company_namethat is namedcompany_name?$company_name->company_name