Setting Key Correctly

4 posts by 2 authors in: Forums > CMS Builder
Last Post: January 28, 2013   (RSS)

I need the first key to change the class for an accordian effect

I can set it up the way I think it should but I keep getting a line error and I can't seem to fix it....

Code:

<div class="accordion" id="accordion2"><?php foreach ($side_newsRecords as $key=>$record): ?>
<div class="accordion-group">
<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapse<?php echo $key;?>"><?php echo htmlencode($record['title']) ?></a> </div>
<div id="collapse<?php echo $key;?>" <?php if ($key == 0) { echo "class='accordion-body collapse'"; } ?>><?php else>"class=accordion-body collapse in" <?php endif ?>
<div class="accordion-inner"><?php echo $record['content']; ?></div>
</div>
</div><?php endforeach ?>
</div>

Thanks in advance,

Michael

Michael Moyers



Owner of Just Rite Design Inc. A growing network of professionals in web design, graphic design, flash development, programming, and audio & video productions.



"Due to budget constraints, the Light at the end of the tunnel will be temporarily out!"

By gregThomas - January 28, 2013 - edited: January 28, 2013

Hi Michael,

I can't see anything that looks obviously wrong. What is the line error you're getting?

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Michael,

I've found out what the problem is. Here is the corrected line:

<div id="collapse<?php echo $key;?>" <?php if ($key == 0): echo "class='accordion-body collapse'"; else: ?>"class=accordion-body collapse in"  <?php endif ?>> 

The problem was that you had a question mark at the start of the else statement.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com