I am trying to select some images from mysql and need to store result in an array.
This is my WHILE loop so far:
// Fetch all the records:
while ($stmt->fetch()) {
$result = "<div class='item'>\n";
$result .= " <div class='gallery_image'>\n";
$result .= " <a class='thumbnail lightbox' title='{$db_restaurant_name}' rel='gal' target='_blank' href='{$image_path}{$image}'>\n";
$result .= " <div class='img-holder' style='background-image:url({$image_path}{$image})'></div>\n";
$result .= " </a>\n";
$result .= " </div>\n";
$result .= "</div>\n";
$gallery[] = $result;
}
}
My question is, I want to add a CSS class named active to first element of this $gallery array. This class need to be add to this line <div class='item'>\n"; Like this class="item active"
UPDATE:
$count = 0;
// Fetch all the records:
while ($stmt->fetch()) {
if($image_type == 0) {
$class = '';
if($count === 0) {
$class = ' active';
}
$result = "<div class='item {$class}'>\n";
$result .= " <div class='gallery_image'>\n";
$result .= " <a class='thumbnail lightbox' title='{$db_restaurant_name}' rel='gal' target='_blank' href='{$image_path}{$image}'>\n";
$result .= " <div class='img-holder' style='background-image:url({$image_path}{$image})'></div>\n";
$result .= " </a>\n";
$result .= " </div>\n";
$result .= "</div>\n";
$gallery[] = $result;
}
$count++;
}
Can anybody tell me how I do this?
Thank you.