CodeIgniter Forums
How do i convert this? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How do i convert this? (/showthread.php?tid=64598)



How do i convert this? - littlefeather - 03-10-2016

How do i get this working i receive this error 
Quote:Cannot use object of type stdClass as array
with the below snippet the issue seems to be with the foreach. 

Code:
$result = $zgrid->query("SELECT * FROM parcels WHERE $category " .
            "(parcelname LIKE '%$text%'" .
            " OR description LIKE '%$text%')" .
            $type . " ORDER BY $order parcelname" .
            " LIMIT ".(0+$query_start).",101");

    $data = array();
    foreach($result->result() as $row ){
        $data[] = array(
                "parcel_id" => $row["infouuid"],
                "name" => $row["parcelname"],
                "for_sale" => "False",
                "auction" => "False",
                "dwell" => $row["dwell"]);
    }



RE: How do i convert this? - acsv - 03-10-2016

Try "parcel_id"=> $row->infouuid (ie reference it as an object, not an array.

I'm just guessing here.


RE: How do i convert this? - cartalot - 03-10-2016

this returns an object
PHP Code:
$result->result() 

this returns an array
PHP Code:
$result->result_array() 

http://www.codeigniter.com/user_guide/database/results.html