Page 1 of 1

Adding object into object list

Posted: Sun Feb 03, 2008 4:00 am
by itsthetaste
Hi,

This is probably really easy, but my PHP skills arent very good so any assistance would be most welcome.

I have a db query like this.
$query = "SELECT imagesrc FROM #__adverts_images WHERE advertid = ".(int) $row->id;
$db->setQuery($query);
$imagerows = $db->loadObjectList();

i am then placing the $imagerows into a session variable like this;

$_SESSION['images'] = $imagerows;

then I want to add a new record into the object list like this;

$_SESSION['images'][count($_SESSION['images'])] = array("imagesrc"=>'image.jpg');

then im passing this array to a function that outputs the list of images like this;

function showImages($images) {
    foreach($images as $image)
    {
    ?>

        }
  }

The images loaded directly from the database show fine.  But I cant get the dynamically added image to show.
I belive it is because I have formated the object wrongly, but I dont know how to fix.

Thanks
Richard

Re: Adding object into object list

Posted: Sun Feb 03, 2008 2:05 pm
by itsthetaste
OK, after a few more hours I found i could do it like this.

$newimage = new stdClass;
$newimage->imagesrc = 'image.jpg';
         
$_SESSION['images'][count($_SESSION['images'])] = $newimage;

So it was the format. :)