Fatal error: Cannot use object of type stdClass as array in line 33

Please help... it seems the error is in

$agentList = array();

i just want to echo the list in my view

Please help... Please help... Please help...

$this->load->model('home_model');
        $agent= $this->home_model->getAgent($data['userID']);
        $agentList = array();
        $listAgent = '';

        if($agent !== FALSE)
        {
            foreach ($agent->result() as $row)
            {
                array_push($agentList, $row['AgentCode']);
                $listAgent .= "<option value='".$row->AgentCode."'>".$row->Name."</option>";
            }
        }

        $listSchool = $this->home_model->getAllSchool($agentList);
        $listTD = '';
        if($listSchool !== FALSE)
        {
            foreach ($listSchool->result() as $row)
            {
                $address = $row->Address." ".$row->Address2;
                $listTD .=  "<tr>
                                <td class='schoolCode' data-comp='".$row->CompanyName."' data-kpID='".$row->KeyPersonID."'>".$row->No_."</td>
                                <td>".$row->Name."</td>
                                <td>".$address."</td>
                                <td class='schoolCode2'>".$row->SecondaryCode."</td>
                                <td>".$row->SegmentName."</td>
                            </tr>";
            }
        }

        $data['returnData'] = array("listAgent" => $listAgent, "listTD" => $listTD);
        $this->load->view('home',$data);

Upvotes: 0

Views: 65

Answers (1)

purpleninja
purpleninja

Reputation: 374

Here you are using $row as both an object and an array (which is where your error message comes from I assume).

foreach ($agent->result() as $row)
        {
            array_push($agentList, $row['AgentCode']);
            $listAgent .= "<option value='".$row->AgentCode."'>".$row->Name."</option>";
        }

Change to:

array_push($agentList, $row->AgentCode);

Upvotes: 2

Related Questions