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
views:
68answers:
4
+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
2010-07-25 16:27:41
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
2010-07-25 16:30:38
Thanks!! This worked like a charm!!! Cheers
jusko
2010-08-03 09:48:37
+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
2010-07-25 16:32:14
+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
2010-07-25 16:47:53