Undefined Variable Error

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

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: [dccreatives] Undefined Variable Error

By Jason - May 11, 2011

Hi,

Another option would be to limit your query to only one result and then put the first record in it's own variable.

For example:
// load records
list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
'limit' => 1,
));

$galleryRecord = $galleryRecords[0]; // get first record.


You can then use the variable $galleryRecord without needing a foreach loop.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

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