I retrieve information from a database and i create a table.
I have a column name Status and almost all of its values is equal to 'A'.
There are some values though that are equal to 'C'. I want the rows that the column of status is equal to 'C' the background color to be red.
my code doesn't seem to work and i think is the javascript part.
Any help is welcome.
My code is this:
<thead>
<tr>
<th>Dongle</th>
<th>ActDate</th>
<th>ModDate</th>
<th>Client</th>
<th>Company</th>
<th>Activation</th>
<th>Comments</th>
<th>Status</th>
</tr>
</thead>
<SCRIPT type="text/javascript">
$(document).ready(function(){
$('table tr').each(function(){
if($(this).find('td').eq(3).text() == 'C'){
$(this).css('background','red');
}
});
});
</SCRIPT>
<?php
$queryString = $_SESSION['clientid'];
$Server = "212.50.99.130\sqlexpress";
$user = "sa";
$password = "sql";
$database = "Licenses";
$connectionInfo = array( "Database"=>$database,"UID"=>$user, "PWD"=>$password);
$link = sqlsrv_connect($Server, $connectionInfo);
if ($link === false) {
echo "Connection failed. \n";
die(print_r(sqlsrv_errors(), true));
}
$Reseller = $_SESSION["Seller"];
$strSQLSel= "SELECT Dongle AS Dongle, ActDate AS ActDate,
ModDate AS ModDate, Client AS Client, Company AS Company,
Activation AS Activation,
Comments AS Comments, Status AS Status
FROM Licenses
WHERE Reseller = '$Reseller'
GROUP BY Dongle,ActDate,ModDate,Client,Company,Activation,Comments,Status";
$result = sqlsrv_query($link,$strSQLSel);
While ($row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC)){
?>
<tbody>
<tr>
<td><p><?php echo $row['Dongle']; ?></p></td>
<td><p><?php echo date_format($row['ActDate'],'Y-m-d'); ?></p></td>
<td><p><?php echo date_format($row['ModDate'],'Y-m-d'); ?></p></td>
<td><p><?php echo $row['Client']; ?></p></td>
<td><p><?php echo $row['Company']; ?></p></td>
<td><p><?php echo $row['Activation']; ?></p></td>
<td><p><?php echo $row['Comments']; ?></p></td>
<td><p><?php echo $row['Status']; ?></p></td>
</tr>
<?php
}
?>
</tbody>
</table>
CSS:
tr.red-status {background-color: red;}
PHP template, table tbody:
<tbody>
<?php
$result = sqlsrv_query($link, $strSQLSel);
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) :
?>
<tr class="<?php echo ($row['Status'] == 'C') ? 'red-status' : '' ?>">
<td><p><?php echo $row['Dongle']; ?></p></td>
<td><p><?php echo date_format($row['ActDate'],'Y-m-d'); ?></p></td>
<td><p><?php echo date_format($row['ModDate'],'Y-m-d'); ?></p></td>
<td><p><?php echo $row['Client']; ?></p></td>
<td><p><?php echo $row['Company']; ?></p></td>
<td><p><?php echo $row['Activation']; ?></p></td>
<td><p><?php echo $row['Comments']; ?></p></td>
<td><p><?php echo $row['Status']; ?></p></td>
</tr>
<?php endwhile; ?>
</tbody>