php - Displaying distinct data from database -
i want php code displaying data database , want add specific class first <li>
.
below statc form of it, want dynamically mysql database.
<ul class="photo"> <li class="first"><a href=""><img src="images/image1.jpg" alt="" /></a></li> //only first line giving attribute (class="first") <li><a href=""><img src="images/image2.jpg" alt="" /></a></li> <li><a href=""><img src="images/image3.jpg" alt="" /></a></li> </ul> <ul class="text"> <li class="first"> <h2><a href="">image 1 caption</a></h2> <p>story............</p> <a class="next" href="">next>></a> </li> <li> // caption line giving attribute (class="first") <h2><a href="">image 2 caption</a></h2> <p>stories 2.................</p> <a class="next" href="">next>></a> </li> <li> <h2><a href="">image 3 caption</a></h2> <p>image 3 story................</p> <a class="next" href="">next>></a> </li> </ul>
assuming hava array of data db:
<?php $first = true; foreach ($array $item) { ?> <li <?php if ($first) { echo "class='first'"; $first = false; } ?>> <h2><?php echo $item["someheader"]; ?></h2> </li> <?php } ?>
this loop through rows db, , assign first class first row in list.
Comments
Post a Comment