1
我从数据库中检索信息,并创建一个表格。 我有一个列名称状态,它的几乎所有值都等于'A'。 虽然有些值等于'C',但有些值。我希望状态栏等于'C'的背景色为红色。在表格行中搜索COLUMN和HIGHLIGHT中的特定文本
我的代码似乎不工作,我认为是JavaScript的一部分。
任何帮助,欢迎。
我的代码是这样的:
<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>
'
<?php echo $ row ['Status'];?>
更改'if($(this).find('td')。 eq(3).text()=='C'){'to'if($(this).find('td:last-child p')。text()=='C'){'and move '
'out of while loop。 –没有没有工作,但谢谢你尝试 –
回答
CSS:
PHP模板,表TBODY:
来源
2016-07-28 08:59:59
它有点工作。值状态中的字母'C',但只有其中一个变为红色 –
“状态”中是否有更多空格?也许使用修剪功能:'<?php echo(trim($ row ['Status' ])=='C')?'red-status':''?>' –
不,我没有空格,我用过修剪但仍然只有两个中的一个 –
更改您的代码以
来源
2016-07-28 08:49:47 jeff
移动
out while循环。 –@ThinkDifferent - 谢谢 - 我错过了那一个:-) – jeff
尝试:
来源
2016-07-28 08:54:42 rad11
来源
2016-07-29 06:39:54
相关问题