Setting Key Correctly
4 posts by 2 authors in: Forums > CMS Builder
Last Post: January 28, 2013 (RSS)
By Mohaukla - January 27, 2013
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
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
PHP Programmer - interactivetools.com
By Mohaukla - January 28, 2013 - edited: January 28, 2013
Parse error: syntax error, unexpected T_ELSE in D:\HostingSpaces\rileytours\rileytours.com\wwwroot\about2.php on line 204
This line: I did fix part of it because some of the sequence was on the outside of the dive tag ... so it looks a little different from the one above
<div id="collapse<?php echo $key;?>" <?php if ($key == 0) { echo "class='accordion-body collapse'"; } ?><?php else?>"class=accordion-body collapse in" <?php endif ?>>
I am thinking it is the echo inside the "If" tag so it is not looking for an "else" tag .... But without it inside what would the code look like?
Michael
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!"
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
PHP Programmer - interactivetools.com