Undefined Variable Error

7 posts by 3 authors in: Forums > CMS Builder
Last Post: May 12, 2011   (RSS)

By dccreatives - May 11, 2011 - edited: May 11, 2011

I have a field called 'mounting' within my section editor called Gallery.

I want to have the page call the mounting in the title of my page.

I inserted this code on the top of the page:

<?php echo $galleryRecord['mounting'] ?> Gallery Images

I am getting the following error: Notice: Undefined variable: galleryRecord in /services/webpages/a/x/axislighting.com/public/CMS/GalleryList.php on line 98 Gallery Images

I used this syntax for most of my pages and I never got an error.

Please advise.

I uploaded the file and here it is online:

http://www.axislighting.com/CMS/GalleryList.php?mounting=pendant

Note: When I put in a foreach statement before the whole table it worked, but then looped my table again and again.

Where should I define the variable that it should not loop?
Attachments:

gallerylist.php 6K

Re: [dccreatives] Undefined Variable Error

By gkornbluth - May 11, 2011

H dccreatives,

It would seem that you will need a foreach loop in order to pull records from a list of records.

You can use a <?php break ?> before the endforeach to stop the looping after the first record.

Hope that gets you going in the right direction.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Undefined Variable Error

By dccreatives - May 11, 2011

Can you please give me an example of how to use it?

Re: [dccreatives] Undefined Variable Error

By gkornbluth - May 11, 2011

Hi,

Something like

At the top of the page:
// load records
list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',



In your table:
<?php foreach ($galleryRecords as $record): ?>
<?php echo $record['mounting'] ?> Gallery Images
<?php break ?>
<?php endforeach ?>


Good luck,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Undefined Variable Error

By dccreatives - May 12, 2011

Thank You. It worked perfectly.

Re: [Jason] Undefined Variable Error

By gkornbluth - May 12, 2011

Jason,

Thanks for the reminder.

It certainly is a much simpler approach.

I guess that's the difference between someone who really understands PHP coding, and those of us who just cobble solutions together using our limited number of tools.

I'll definitely include this approach in the Cookbook.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php