views:

68

answers:

4

Hi everybody, 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

+2  A: 

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

Shubham
A: 

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.
}
kander
Thanks!! This worked like a charm!!! Cheers
jusko
+1  A: 

Use a counter:

$i = 1;

while ($row = mysql_fetch_assoc($result))
{
    if ($i == 1)
    {
        echo '<li class="visible">';
    }
    else
    {
        echo '<li class="hidden">';
    }

    // Print the rest of your output for each row here

    $i++;
}
BoltClock
+2  A: 

It can be done more shortlier like this:

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