'how to change row background on table which is populated from mysql depending on one parameter
Does anyone know how to change the row background depending on the data I get from MySQL database? This is my PHP which I then call in my html. I use datatables but I can remove them if theres the problem.
while($row = mysqli_fetch_array($result)) {
if ($row['VRSTA'] == 1) echo '<tr style="background-color:#000000">';
if ($row['VRSTA'] == 2) echo '<tr style="background-color:#ffff99">';
if ($row['VRSTA'] == 3) echo '<tr style="background-color:#ff2f99">';
echo "<tr>";
echo "<td>" . $row['IME'] . "</td>";
echo "<td>" . $row['PRIIMEK'] . "</td>";
echo "<td>" . $row['EMAIL'] . "</td>";
echo "<td>" . $row['TELEFON'] . "</td>";
echo "<td>" . $row['KRAJ_DELOVANJA'] . "</td>";
echo "<td>" . $row['STATUS_CLANA'] . "</td>";
echo "<td>" . $row['DATUM'] . "</td>";
echo "</tr>";
}
HTML:
<script>
$(document).ready(function() {
$.ajaxSetup({ cache: false });
setTimeout(function() {
$('#mainResults').load('vse_prijave_php.php');
setTimeout(function(){
$('#mainResults').DataTable();
},1000);
}, 1000);
});
</script>
<div id="results">
<table border='1' id="mainResults">
<td>Loading data ...</td>
</table>
</div>
Solution 1:[1]
You must write on the tds, tr inline style may disabled. Or define class like tr.blabla td{} after than write to tr class variable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sametcilli |
