conditional question

2 posts by 2 authors in: Forums > CMS Builder
Last Post: July 28, 2011   (RSS)

By rez - July 28, 2011

at the top of my page i have:
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '2',
));
list($eventsRecords, $eventsMetaData) = getRecords(array(
'tableName' => 'events',
'limit' => '2',
));


If there arent any events, i would like to show 4 news items to fill the space. I dont know if the code should go up top, after the events is ran?

<?php if (!$eventsRecords): ?>
'limit' => '2',
<?php else ?>
'limit' => '4',
<?php endif ?>


or limit 4 in the top and only show 2 with a loop in the body if there aren't event items.. which seems inefficient if the numbers get larger? if this is the way to do it, please let me know how. a counter or something? hoping for an example of the best approach. :)

thank you