我使用php/html顯示了一些來自mysql數據庫的值。在我的表中,我有一個字段「事務類型」(txn_type)。我在交易類型(購買和退款)中有兩種類型的交易。是否有可能根據交易類型中的值更改css類?例如基於表中的php/mysql查詢輸出值更改css類
if the value is purchase I need to execute this:
<td><span class="label label-info label-mini"><?php echo $type ?></span></td>
If it is Refund I need to execute this:
<td><span class="label label-success label-mini"><?php echo $type ?></span></td>.
如果可能,請儘可能。 附加我的代碼。
<table class="table table-striped table-advance table-hover" id="dataTables-example">
<thead>
<tr>
<th><i class="fa fa-bullhorn"></i> Type</th>
<th class="hidden-phone"><i class="fa fa-calendar"></i> Date</th>
<th><i class="fa fa-rupee"></i> Amount</th>
<th><i class=" fa fa-book"></i> Details</th>
<th><i class=" fa fa-calendar-o"></i> Due Date</th>
<th><i class=" fa fa-history"></i> Action</th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($GLOBALS["___mysqli_ston"], "select * from dlbcc_purchase order by date(purch_date)desc")or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
while ($row = mysqli_fetch_array($query)) {
$id = $row['id'];
$type = $row['txn_type'];
$date = $row['purch_date'];
$amount = $row['purch_amt'];
$dtls = $row['purch_dtls'];
$due = $row['due_date'];
?>
<tr>
<td><span class="label label-success label-mini"><?php echo $type ?></span></td>
<td><?php echo $date ?></td>
<td><?php echo $amount?></td>
<td><?php echo $dtls ?></td>
<td><span class="label label-warning label-mini"><?php echo $due ?></span></td>
<td>
<button class="btn btn-primary btn-xs"><i class="fa fa-pencil"></i></button>
<button class="btn btn-danger btn-xs"><i class="fa fa-trash-o "></i></button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
感謝您的支持....它按預期工作。 – 2014-10-30 10:39:05