Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm getting the error "Fatal error: Cannot use object of type stdClass as array in" on line 183 which happens to be

$getvidids = $ci->db->query("SELECT * FROM videogroupids WHERE videogroupid='$videogroup' AND used='0' LIMIT 10");
foreach ($getvidids->result() as $row){
    $vidid = $row['videoid'];
}

Anyone know what's wrong with the above code? Or what this error means?

share|improve this question

2 Answers

up vote 20 down vote accepted

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;
}
share|improve this answer
Thank you! Surprised I didn't catch that... – kyle Mar 23 '11 at 23:56

if you really want an array instead you can use:

$getvidids->result_array()

which would return the same information as an associative array.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.