Wise Posted December 7, 2013 Group: Members Topic Count: 46 Topics Per Day: 0.01 Content Count: 147 Reputation: 26 Joined: 11/19/11 Last Seen: October 28, 2021 Share 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: Link to comment Share on other sites More sharing options...
Digos Posted December 8, 2013 Group: Members Topic Count: 12 Topics Per Day: 0.00 Content Count: 88 Reputation: 23 Joined: 01/30/12 Last Seen: February 19 Share 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. Link to comment Share on other sites More sharing options...
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:
Link to comment
Share on other sites
1 answer to this question
Recommended Posts