I need to add a different style to each row displayed from mysql. I am displaying last 4 rows and starting from the first row, the styles should be called first, second, third, fourth.
<?php
$sql = "SELECT * FROM articles ORDER BY id DESC LIMIT 4";
$result = $con->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '
<div class="ot-slider-layer first">
<a href="articles/'.$row['slug'].'">
<strong><i style="background-color: #ed2d00; color: #fff;">'.category_name_by_id($row['category']).'</i>'.$row['title'].'</strong>
<img src="images/articles/'.$row['image'].'" alt="'.$row['title'].'" />
</a>
</div>
';
}
} else {
echo "There is no news";
}
?>
whileloop and set yourclassor whatever accordingly. Alternatively you could add like(@row_number:=@row_number + 1) AS numinto yourSELECTstatement and use that to determine your style class/id/whatever.