Creating a if statement inside of a foreach loop

5 posts by 3 authors in: Forums > CMS Builder
Last Post: April 25, 2014   (RSS)

By Chris - April 24, 2014

Hi drewh01,

That's definitely possible, and you're going about it the right way. Did you add a getRecords() call to load the $film_list_page_controlsRecord variable at the top of the page?

// load record from 'site_general_information'
list($film_list_page_controlsRecords, $film_list_page_controlsMetaData) = getRecords(array(
  'tableName'   => 'film_list_page_controls',
  'where'       => '', // load first record
  'loadUploads' => true,
  'allowSearch' => false,
  'limit'       => '1',
));
$film_list_page_controlsRecord = @$film_list_page_controlsRecords[0]; // get first record
if (!$film_list_page_controlsRecord) { dieWith404("film_list_page_controls record not found!"); } // show error message if no record found

Does that help? If not, please post the PHP source code for your page as an attachment.

All the best,
Chris

By drewh01 - April 24, 2014

I tried that but get errors.

http://illuminatefilmfestival.com/films_test.php

Attached is the source code. But here is the part of the code that I am trying to work with:

<?php if ($film_list_page_controlsRecord['show_table_row']): ?>
<tr>
<td><?php if ($film_list_page_controlsRecord['date_time']): ?>
<?php if ($record['screening_time']): ?>
<span style="color:#05387F"><?php echo date("D, M jS g:i a", strtotime($record['screening_time'])) ?></span>
<?php endif ?>
<?php endif ?></td>

<td height="0"></td>

<td width="223"><?php if ($film_list_page_controlsRecord['screening_venue']): ?>
<?php if ($record['screening_venue']): ?>
<a href="http://illuminatefilmfestival.com/venues"><?php echo $record['screening_venue'] ?>
</a><?php endif ?>
<?php endif ?></td>

<td width="104"><?php if ($film_list_page_controlsRecord['more_info']): ?><br />
[<a href="<?php echo $record['_link'] ?>">More Info</a>]
<?php endif ?></td>
</tr>
<?php endif ?>

Hopefully you can see what I am trying to do. I was hoping to be able to set up a section where I can globally turn on and off specific parts of the list elements.

Thanks!!!

By rconring - April 25, 2014

As Chris pointed out, You need to add this line of code to films_test.php after the viewer in order to place the first record in the film_list_page_controlRecord array:

$film_list_page_controlsRecord = @$film_list_page_controlsRecords[0]; // get first record

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

By drewh01 - April 25, 2014

Got it, thanks!!!!