Adding object into object list

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
itsthetaste
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Jan 18, 2008 2:32 am

Adding object into object list

Post by itsthetaste » Sun Feb 03, 2008 4:00 am

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

itsthetaste
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Jan 18, 2008 2:32 am

Re: Adding object into object list

Post by itsthetaste » Sun Feb 03, 2008 2:05 pm

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. :)


Post Reply