Problem with foreach

4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 23, 2010   (RSS)

Re: [Djulia] Problem with foreach

By Chris - March 19, 2010

Hi Djulia,

You have two options here.

(1) you can drop foreach and reference the elements directly:

<image_0><?php echo @$record['images'][0]['urlPath']; ?></image_0>
<image_1><?php echo @$record['images'][1]['urlPath']; ?></image_1>
<image_2><?php echo @$record['images'][2]['urlPath']; ?></image_2>
<image_3><?php echo @$record['images'][3]['urlPath']; ?></image_3>


Alternately, (2) you can use a counter variable to output the numbers in your tags:

<?php $count = 0 ?>
<?php foreach ($record['images'] as $upload):?>
<image_<?php echo $count ?>><?php echo $upload['urlPath'] ?></image_<?php echo $count ?>>
<?php $count++ ?>
<?php endforeach ?>


Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Problem with foreach

By Djulia - March 23, 2010 - edited: March 23, 2010

Hi Chris,

Thanks ! That really helped me! :)

I write a script of importation. That functions correctly, but I did not really understand the interest of preSaveTempId.
Is this column used at the time of the
[font "Times New Roman"]downloading of the files?

Thank you for the feedback ! :)

Djulia

Re: [Djulia] Problem with foreach

By Chris - March 23, 2010

Hi Djulia,

preSaveTempId is used internally by CMS Builder to keep track of uploads which belong to a record which does not exist yet.

For example, when a user is creating an article (and has not saved it yet,) they can upload files. Those files are stored with a unique preSaveTempId so that when the record is saved, they can be associated with the new record number. This is only an issue because record numbers are only assigned when records are saved.

Once a record has been saved, the preSaveTempId is ignored.

You shouldn't have to worry about preSaveTempId at all; you can just leave it blank.

I hope this helps. Please let me know if you have any questions.
All the best,
Chris