Wise Posted December 7, 2013 Posted December 7, 2013 Can someone help me out with this? <?php foreach($news as $nrow):?> <div id="header" class="accordion_headings" ><?php echo $nrow->title ?></div> <div id="content"> <p><?php echo $nrow->body ?></p> </div> <?php endforeach;?> My question is how to generate a specific div id for each $nrow? could be for the first $nrow, name it header_1 so that I can put div id="$nrow->id" halp D:
Digos Posted December 8, 2013 Posted December 8, 2013 It can be: <?php $index = 0; foreach($news as $nrow) { echo "<div id=\"header_".$index."\" class=\"accordion_headings\">".$nrow->title."</div>"; echo "<div id=\"content_".$index."\">"; echo "<p>".$nrow->body."</p>"; echo "</div>"; $index++; } ?> The output will be header_0:content_0, header_1:content_1, .... until it reach the foreach size.
Question
Wise
Can someone help me out with this?
My question is how to generate a specific div id for each $nrow?
could be for the first $nrow, name it header_1 so that I can put div id="$nrow->id"
halp D:
1 answer to this question
Recommended Posts