I'm getting the error:
"Fatal error: Cannot use object of type stdClass as array in" on line 183
From this code:
$getvidids = $ci->db->query( "SELECT * FROM videogroupids " . "WHERE videogroupid='$videogroup' AND used='0' LIMIT 10"); foreach ($getvidids->result() as $row){ $vidid = $row['videoid']; //This is line 183 }
Anyone know what's wrong with the above code? Or what this error means?
The stdClass is the empty class in PHP which is used to cast other types to object. It is similar to Java or Python object. The stdClass is not the base class of the objects. If an object is converted to object, it is not modified.
You create StdClass objects and access methods from them like so: $obj = new StdClass; $obj->foo = "bar"; echo $obj->foo; I recommend subclassing StdClass or creating your own generic class so you can provide your own methods. Thank you for your help!
CodeIgniter returns result rows as objects, not arrays. From the user guide:
result()
This function returns the query result as an array of objects, or an empty array on failure.
You'll have to access the fields using the following notation:
foreach ($getvidids->result() as $row) { $vidid = $row->videoid; }
if you really want an array instead you can use:
$getvidids->result_array()
which would return the same information as an associative array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With