1

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

1
  • 2
    Why was this voted down? And would someone please fix the title, so that it's a better representation of the question? Commented Jul 25, 2010 at 16:35

3 Answers 3

2

Well thats easy! Just track the row number, if it is the first row then echo out class="visible" else class='hidden"

Sign up to request clarification or add additional context in comments.

Comments

2

It can be done more shortlier like this:

$i = 1;
while ($row = mysql_fetch_assoc($result)) {
    echo '<li class="' . (($i == 1) ? 'visible' : 'hidden') . '">';
    $i++;
}

Comments

0

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.
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.