Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

php - Fatal error: Cannot use object of type stdClass as array in

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...