【发布时间】:2014-10-30 09:53:41
【问题描述】:
我正在使用 php/html 显示 mysql 数据库中的一些值。在我的表中,我有一个字段“交易类型”(txn_type)。我在交易类型字段中有两种交易类型(购买和退款)。是否可以根据事务类型中的值更改 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>
【问题讨论】: