Check for last-record in list-viewer
2 posts by 2 authors in: Forums > CMS Builder
Last Post: January 23, 2009 (RSS)
By avrom - January 23, 2009
Hi Dave,
I am sure there is a simple php function to test for the last record in a list-viewer.
I just want to check if a record is the last in a list-viewer. If it is I don't want to print the extra &8226; character in the menu line...
<?php foreach ($sub_galleriesMenus as $record): ?>
<a href="#"><?php echo $record['gallery_name'] ?></a> •
<?php endforeach ?>
Thanks in advance !!
Avrom
I am sure there is a simple php function to test for the last record in a list-viewer.
I just want to check if a record is the last in a list-viewer. If it is I don't want to print the extra &8226; character in the menu line...
<?php foreach ($sub_galleriesMenus as $record): ?>
<a href="#"><?php echo $record['gallery_name'] ?></a> •
<?php endforeach ?>
Thanks in advance !!
Avrom
Re: [virgodesign] Check for last-record in list-viewer
By Dave - January 23, 2009
Hi Avrom,
Try this:
When you have an array (list) of records you can refer to them by number like this: $array[1], etc. Except it starts at zero. You can also refer to the last item in the list with -1. So this checks if the current record number being displayed has the same number as the last records number.
Let me know if that works for you.
Try this:
<?php foreach ($sub_galleriesMenus as $record): ?>
<a href="#"><?php echo $record['gallery_name'] ?></a> •
<?php $isLastRecord = $record['num'] == $sub_galleriesMenus[-1]['num'] ?>
<?php if (!$isLastRecord): ?> • <?php endif ?>
<?php endforeach ?>
When you have an array (list) of records you can refer to them by number like this: $array[1], etc. Except it starts at zero. You can also refer to the last item in the list with -1. So this checks if the current record number being displayed has the same number as the last records number.
Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com
interactivetools.com