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:
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?
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
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
Re: [rez] conditional question
By Jason - July 28, 2011
Hi,
One approach you can take, is to select your event records first and then, based on the results you get back, set a limit for your query to the news table.
For example:
Hope this helps
One approach you can take, is to select your event records first and then, based on the results you get back, set a limit for your query to the news table.
For example:
list($eventsRecords, $eventsMetaData) = getRecords(array(
'tableName' => 'events',
'limit' => '2',
));
if ($eventsRecords) {
$newsLimit = 2;
}
else {
$newsLimit = 4;
}
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => $newsLimit,
));
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/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/