markup help

2 posts by 2 authors in: Forums > CMS Builder
Last Post: November 26, 2012   (RSS)

By KCMedia - November 26, 2012

Hi

I have this piece of code

<?php foreach ($contact_usRecords as $listRecord): ?>
<?php $isSelected = ($listRecord['num'] == $detailRecord['num']); ?>
<?php if ($isSelected) { print "<b>"; } ?>
<li><a href="<?php echo htmlencode($listRecord['_link']) ?>"><?php echo htmlencode($listRecord['state_code']) ?></a></li>
<?php if ($isSelected) { print "</b>"; } ?>
<?php endforeach ?>
<?php if (!$contact_usRecords): ?>
<?php endif ?>

at the moment it bolds the selected item but i want it to not bold the selected item but to set the class on the <li> to class="active" how can i do that?
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] markup help

By gregThomas - November 26, 2012

Hi craig,

Something like this should do the job:

<?php foreach ($contact_usRecords as $listRecord): ?>

<li <?php echo ($listRecord['num'] == $detailRecord['num'])? 'class="active"' :''; ?> >
<a href="<?php echo htmlencode($listRecord['_link']) ?>"><?php echo htmlencode($listRecord['state_code']) ?></a>
</li>
<?php endforeach ?>
<?php if (!$contact_usRecords): ?>
<?php endif ?>


So when $listRecord['num'] is equal to $detailsRecord['num'] class="active" is shown, otherwise nothing is displayed.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com