How to Make PHP Code Blocks Unique?

2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 22, 2008   (RSS)

By Perchpole - September 22, 2008

Hello, All

I am constructing a page design which uses data drawn from a single SQL table but which I would like to use in two different ways (on the same page). In order to do this, the PHP code block at the top of the page must have different parameters. For example:

Block A

list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',

));


Block B

list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$galleryRecord = @$galleryRecords[0]; // get first record




In both instances the resulting data would be presented on screen using the same code - something like:

<?php foreach ($galleryRecords as $record): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
<?php endforeach ?>


Obviously, if I leave it like this, there'll be a conflict. My question is, how do I "rename" the code blocks in such a way as to differentiate between the two?

I've tried a little experiment and inserted an extra digit into one of the blocks as shown below...

list($gallery2[/#ff0000]Records, $gallery2[/#ff0000]MetaData) = getRecords(array(
'tableName' => 'gallery',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$galleryRecord = @$gallery2[/#ff0000]Records[0]; // get first record




This seems to work - but is it the right way?

:0/

Perch

Re: [Perchpole] How to Make PHP Code Blocks Unique?

By Dave - September 22, 2008

Hi Perch,

Yes, that works just fine - and is probably what we'll update the code generator to do automatically at some future point.

Let us know if you need anything else! :)
Dave Edis - Senior Developer
interactivetools.com