I´m fetching my database for images to create a gallery. Every row appear inside a <li>
. My question is, is it possible, that the first <li>
have a class (for example, "visible"
), and all the other <li>
have a class named "hidden"
. So the first $row
would have a different class than the following... Hope I made myself clear! Thanks
How about something like
$visible = true;
while(...) {
if($visible) {
echo "<li class='visible'>";
else {
echo "<li class='hidden'>";
}
$visible = false; // Every loop sets it to false, which after the first one will make no difference.
}
Well thats easy! Just track the row number, if it is the first row then echo out class="visible" else class='hidden"
It can be done more shortlier like this:
$i = 1;
while ($row = mysql_fetch_assoc($result)) {
echo '<li class="' . (($i == 1) ? 'visible' : 'hidden') . '">';
$i++;
}