简体   繁体   中英

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);

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM