我有一个动态表,其中id="complaint_status"
字段值只能"PENDING"
和"CLEARED"
。
请根据这些值为字段提供不同的背景颜色:
有没有办法应用条件CSS?
我的代码如下(由于限制,我无法包含所有代码):
<?php require_once('Connections/my_connection.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--[if IE 6]><link href="default_ie6.css" rel="stylesheet" type="text/css" /><![endif]-->
<link href="jquery.ui-1.5.2/themes/ui.datepicker.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#content table tr td {
text-align: center;
font-weight: bold;
}
#wrapper #page #content table {
color: #000000;
}
#content table {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-transform:uppercase;
}
.link {
font-family: Arial, Helvetica, sans-serif;
color: #000;
}
.pending{
background-color:#F00;
}
.cleared{
background-color:#0F0;
}
</style>
<script src="jquery.ui-1.5.2/jquery-1.2.6.js" type="text/javascript"></script>
<script src="jquery.ui-1.5.2/ui/ui.datepicker.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
// Dynamic Selects by Kaosweaver
// Copyright 2007, All rights reserved
</head>
<body>
<?php
include ('header.php');
?>
<div id="wrapper">
<div id="page" class="container">
<div id="content">
<div class="title">
<h2><a href="#">KNOW YOUR COMPLAINT STATUS</a></h2>
<span class="byline">search your complaints by any of these category</span> </div>
<form id="form1" action="" method="post">
<p>
<fieldset>
<table width="648" height="248" align="center" cellpadding="5" cellspacing="5" dir="ltr">
<tr>
<td width="275" align="left" class="letter"><strong class="letter">Search Complaints by Date:</strong></td>
<td width="187" align="left"><strong class="letter">From:</strong><br />
<input type="text" name="from_date" size="25" id="jQueryUICalendar1" value=Choose...>
<script type="text/javascript">
// BeginWebWidget jQuery_UI_Calendar: jQueryUICalendar1
jQuery("#jQueryUICalendar1").datepicker();
// EndWebWidget jQuery_UI_Calendar: jQueryUICalendar1
</script></td>
<td width="182" align="left"><strong class="letter">To:
</strong><br />
<input type="text" name="to_date" size="25" id="jQueryUICalendar2" value=Choose...>
<script type="text/javascript">
// BeginWebWidget jQuery_UI_Calendar: jQueryUICalendar2
jQuery("#jQueryUICalendar2").datepicker();
// EndWebWidget jQuery_UI_Calendar: jQueryUICalendar2
</script></td>
</tr>
<tr align="left">
<td align="left" class="letter"><strong>Search Complaints by No:</strong></td>
<td colspan="2"><input type="text" name="complaint_no" id="complaint_no" size="25">
</td>
</tr>
<tr>
<td align="left" class="letter"><strong>
<label for="lodged_by">Search Complaints Lodged By:</label>
</strong></td>
<td colspan="2" align="left"><input type="text" name="lodged_by" id="lodged_by" size="25" ></td>
</tr>
<tr>
<td align="left" class="letter"><strong>
<label for="comp_item_sl_no">Search CompIaints by tem Sl No:</label>
</strong></td>
<td colspan="2" align="left"><input type="text" name="comp_item_sl_no" id="comp_item_sl_no" size="25" ></td>
</tr>
<tr>
<td align="left" class="letter">Search By Section:</td>
<td align="left"><span class="letter">
Branch: <br />
<select name="branch" id="branch" style="width:182px">
<option>Choose...</option>
<option value="SASO">SASO</option>
<option value="SMSO">SMSO</option>
<option value="AOC">AOC</option>
<option value="SOA">SOA</option>
<option value="TCU">TCU</option>
<option value="REB">REB</option>
<option value="DCMU">DCMU</option>
<option value="1 P&S">1 P&S</option>
<option value="4 LU">4 LU</option>
<option value="7 ASC">7 ASC</option>
</select>
</span></td>
<td align="left"><span class="letter">
Section:<br />
<select name="section" id="section" style="width:182px">
<option>---------------------------------</option>
</select>
</span></td>
</tr>
<tr align="left">
<td colspan="3" class="letter"></td>
</tr>
</table>
</fieldset>
</p><input name="button" type="submit" class="button" align="left" id="button" onclick="MM_validateForm('complaint_no','','NisNum');return document.MM_returnValue" value="Search" />
</form>
<p></p>
<table border="1" align="center" cellpadding="5" cellspacing="2">
<tr bgcolor="#5C94DF" class="">
<td>COMPLAINT NO</td>
<td nowrap="nowrap">ITEM SL NO</td>
<td nowrap="nowrap">ITEM NAME</td>
<td nowrap="nowrap">INV NO</td>
<td nowrap="nowrap">LODGED BY</td>
<td>COMPLAINT DATE</td>
<td nowrap="nowrap">DESCRIPTION</td>
<td>COMPLAINT STATUS</td>
<td nowrap="nowrap">RECTIFIED BY</td>
<td>RECTIFICATION DATE</td>
<td nowrap="nowrap">REMARKS</td>
</tr>
<?php
$rows = mysql_num_rows($rs_section);
if($rows > 0) {
mysql_data_seek($rs_section, 0);
$row_rs_section = mysql_fetch_assoc($rs_section);
}
?>
<?php
$rows = mysql_num_rows($rs_sl);
if($rows > 0) {
mysql_data_seek($rs_sl, 0);
$row_rs_sl = mysql_fetch_assoc($rs_sl);
}
?>
<?php
$rows = mysql_num_rows($rs_lodged);
if($rows > 0) {
mysql_data_seek($rs_lodged, 0);
$row_rs_lodged = mysql_fetch_assoc($rs_lodged);
}
?>
<?php do { ?>
<?php do { ?>
<?php do { ?>
<?php do { ?>
<tr class="">
<td bgcolor="#FFFFFF" class="link"><strong><a href="admin_complaints_modify.php?complaint_no=<?php echo $row_rs_datewise['complaint_no']; ?>"><?php echo $row_rs_datewise['complaint_no']; ?></a><a href="admin_complaints_modify.php?complaint_no=<?php echo $row_rs_complaint_no['complaint_no']; ?>"><?php echo $row_rs_complaint_no['complaint_no']; ?></a><a href="admin_complaints_modify.php?complaint_no=<?php echo $row_rs_lodged['complaint_no']; ?>"><?php echo $row_rs_lodged['complaint_no']; ?></a><a href="admin_complaints_modify.php?complaint_no=<?php echo $row_rs_section['complaint_no']; ?>"><?php echo $row_rs_section['complaint_no']; ?></a><a href="admin_complaints_modify.php?complaint_no=<?php echo $row_rs_sl['complaint_no']; ?>"><?php echo $row_rs_sl['complaint_no']; ?></a></strong></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['comp_item_sl_no']; ?><?php echo $row_rs_complaint_no['comp_item_sl_no']; ?><?php echo $row_rs_lodged['comp_item_sl_no']; ?><?php echo $row_rs_section['comp_item_sl_no']; ?><?php echo $row_rs_sl['comp_item_sl_no']; ?></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['comp_item_name']; ?><?php echo $row_rs_complaint_no['comp_item_name']; ?><?php echo $row_rs_lodged['comp_item_name']; ?><?php echo $row_rs_section['comp_item_name']; ?><?php echo $row_rs_sl['comp_item_name']; ?></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['inv_no']; ?><?php echo $row_rs_complaint_no['inv_no']; ?><?php echo $row_rs_lodged['inv_no']; ?><?php echo $row_rs_section['inv_no']; ?><?php echo $row_rs_sl['inv_no']; ?></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['lodged_by']; ?><?php echo $row_rs_complaint_no['lodged_by']; ?><?php echo $row_rs_lodged['lodged_by']; ?><?php echo $row_rs_section['lodged_by']; ?><?php echo $row_rs_sl['lodged_by']; ?></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['complaint_date']; ?><?php echo $row_rs_complaint_no['complaint_date']; ?><?php echo $row_rs_lodged['complaint_date']; ?><?php echo $row_rs_section['complaint_date']; ?><?php echo $row_rs_sl['complaint_date']; ?></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['complaint_description']; ?><?php echo $row_rs_complaint_no['complaint_description']; ?><?php echo $row_rs_lodged['complaint_description']; ?><?php echo $row_rs_section['complaint_description']; ?><?php echo $row_rs_sl['complaint_description']; ?></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['complaint_status']; ?><?php echo $row_rs_complaint_no['complaint_status']; ?><?php echo $row_rs_lodged['complaint_status']; ?><?php echo $row_rs_section['complaint_status']; ?><?php echo $row_rs_sl['complaint_status']; ?></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['rectified_by']; ?><?php echo $row_rs_complaint_no['rectified_by']; ?><?php echo $row_rs_lodged['rectified_by']; ?><?php echo $row_rs_section['rectified_by']; ?><?php echo $row_rs_sl['rectified_by']; ?></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['rectification_date']; ?><?php echo $row_rs_complaint_no['rectification_date']; ?><?php echo $row_rs_lodged['rectification_date']; ?><?php echo $row_rs_section['rectification_date']; ?><?php echo $row_rs_sl['rectification_date']; ?></td>
<td nowrap="nowrap"><?php echo $row_rs_datewise['comp_remarks']; ?><?php echo $row_rs_complaint_no['comp_remarks']; ?><?php echo $row_rs_lodged['comp_remarks']; ?><?php echo $row_rs_section['comp_remarks']; ?><?php echo $row_rs_sl['comp_remarks']; ?></td>
</tr>
<?php } while ($row_rs_datewise = mysql_fetch_assoc($rs_datewise)); ?>
<?php } while ($row_rs_lodged = mysql_fetch_assoc($rs_lodged)); ?>
<?php } while ($row_rs_sl = mysql_fetch_assoc($rs_sl)); ?>
<?php } while ($row_rs_section = mysql_fetch_assoc($rs_section)); ?>
</table>
</div>
答案 0 :(得分:1)
我添加了示例css以及如何在代码中使用它。假设您能够连接数据库并成功执行查询。另外,我假设行中只有列。
<style>
.CLEARED{background-color:green;}
.PENDING {background-color:red;}
</style>
<?php
$query="your query";
$resource=mysql_query($query);
echo '<table>';
while($result=mysql_fetch_object($resource)) {
$val=strtoupper($result->complaint_status);
echo '<tr><td id="complaint_status" class="<?php echo $val;?>">$val</td></tr>';
}
echo '</table>';
?>
答案 1 :(得分:0)
正如@ursitesion所说,您可以在查询中使用以下内容:
将此信息包含在您的CSS代码中:
.CLEARED{background-color:green;}
.PENDING{background-color:red;}
Php代码:
//EXAMPLE OF QUERY
echo "<table>";
while($row=mysql_fetch_array($result)){
$cleared='CLEARED';
$pending='PENDING';
$status=$row['status'];
if($status==0)
$status='CLEARED';
else $status='PENDING';
echo "<tr><td id='complaint_status' class='$status'>$val</td></tr>";
}
echo "</table>";
检查它,它必须工作伙计。调整您的查询(;