I created a database i have a table im calling all rows from datatable and im wanting to set all rows color to situation. For example if situation is "ACTIVE" it should change the color green. else situation='PROCESSING' color ='YELLOW' else situation='NONE' color ='RED'
<table class="table" id="table">
<tr>
<th>ID</th>
<th>Company</th>
<th>Situation</th>
</tr>
<?php
$ques = $conn->query("SELECT * FROM company ");
while ($result = $ques->fetch_assoc()) {
$id = $result['id'];
$companyname = $result['companyname'];
$situation = $result['situation'];
?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $companyname; ?></td>
<td><?php echo $situation; ?></td>
</tr>
<?php
}
?>
</table>
<script>
$(document).ready( function() {
$('#table').dataTable( {
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
if ( aData['2'] == "NONE" )
{
$('td', nRow).css('background-color', 'red' );
}
else if ( aData['2'] == "ACTIVE" )
{
$('td', nRow).css('background-color', 'green');
}
else if ( aData['2'] == "PENDING" )
{
$('td', nRow).css('background-color', 'yellow');
}
else
{
$('td', nRow).css('background-color', 'orange');
}
}
} );
} );
</script>
I m expecting the output should be with color
</div>