ooPHP - How do I create an array of objects from an associative array?

trittekew

New Member
I'm not sure if this is even possible after trying to figure it out for hours but here goes...I have an class, UserPicture, which has properties for filename, filetype, created etc. (i.e. it doesn't store the actual picture as a blob, rather references it by using $filename.$filetype).I want to be able to have a page that displays all of a user's pictures, so I need to retrieve all rows from the DB relevant to that user. I've got the associative array out of the DB successfully and have used the following code to create the object, which works as I have tested the output of it by echoing it...\[code\]$result=query("SELECT * FROM pictures WHERE user_id=$user_id");// Returns associative array with numerous succesfully.$pictures = array();foreach($result as $row) { $pictures = new UserPicture($row);}\[/code\]This kinda works but I only get the last row as an object in the array. So I have tried array_push...\[code\]foreach($result as $row) { array_push($pictures, new UserPicture($row));}\[/code\]...and I've tried using $pictures[]=new UserPicture($row), but both just give me the following error...\[quote\] Catchable fatal error: Object of class UserPicture could not be converted to string in user_picture_manage.php on line 72\[/quote\]If anyone could please shed any light on what I'm doing wrong that would be very helpful!Many thanks,Steve
 
Back
Top