Display No.Records in List Viewer

4 posts by 2 authors in: Forums > CMS Builder
Last Post: December 30, 2008   (RSS)

By avrom - December 24, 2008

Hi Dave,

I have a list viewer that will display a number of ads. But instead of just listing all of them or a predetermined number, it will be specified by the client:

<?php echo $site_templateRecord['number_of_ads'] ?>

SO how to combine into the list viewer for the Ads section ?

<?php foreach ($ads_125x125Records as $record): ?>


Thanks Dave :))
Avrom

Re: [virgodesign] Display No.Records in List Viewer

By avrom - December 24, 2008

Hey Dave,

Here is the code I have initially setup. If there are only two or 3 ads actually in the table, but the number_of_ads is 8 then I still want to display the full 8 DIV's with the 3 ads for example. Make sense ?

<?php foreach ($ads_125x125Records as $record): ?>
<?php foreach ($record['ad_upload'] as $upload): ?>

<?php if ( is_int($record['num']/2) )
{ echo '<div id="ad_block" class="block3a"> '; }
else { echo '<div id="ad_block" class="block3b"> '; } ?>
<?php if ($upload['isImage']): ?>
<a href="<?php echo $record['url'] ?>" target="_blank"><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" title="<?php echo $record['sponsor'] ?>" alt="<?php echo $record['sponsor'] ?>" /></a>
<?php endif ?>
</div>

<?php endforeach ?>
<?php endforeach ?>

Re: [virgodesign] Display No.Records in List Viewer

By Dave - December 27, 2008

Hi Avrom,

Try passing the value directly to the getRecords() code like this:

"limit" => (int) $site_templateRecord['number_of_ads'],

The (int) isn't really required, but it will force the value to be a number in case the client enters something else and prevent errors.

Just make sure you load $site_templateRecord first. Let me know if that works and any other issues you have remaining and I'll try and help! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Display No.Records in List Viewer

By avrom - December 30, 2008

Dave,

Figured it out :)) Just ran a second while loop for the ads not in the record, and maintained a counter in both loops.

Thanx :))
Avrom