根据表中的php/mysql查询输出值更改css类

根据表中的php/mysql查询输出值更改css类,php,mysql,css,Php,Mysql,Css,我正在使用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 ?></sp

我正在使用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>.
如果值为purchase,我需要执行以下操作:
如果是退款,我需要执行以下操作:
.
如果可能,请尽可能。 附加我的代码

<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>

类型
日期
数量
细节
到期日
行动

您可以使用PHP来实现这一点。比如:

<?php
if ($type == "purchase") echo $label="label-info";
else if ($type == "refund") echo $label = "label-success";
else // provide some fallback here, if there are more types of transaction
?>

然后回显/显示正确的类别:

<td><span class="label <?php echo $label ?> label-mini"><?php echo $type ?></span></td>

您可以使用PHP来实现这一点。比如:

<?php
if ($type == "purchase") echo $label="label-info";
else if ($type == "refund") echo $label = "label-success";
else // provide some fallback here, if there are more types of transaction
?>

然后回显/显示正确的类别:

<td><span class="label <?php echo $label ?> label-mini"><?php echo $type ?></span></td>
可能吧-

<?php 

   if ( $type == 'purchase ') {
      echo '<td><span class="label label-info label-mini"> ';
   } else {
      echo '<td><span class="label label-success label-mini"> ';
   }
   echo $type
   echo '</span></td>';
?>

也许吧-

<?php 

   if ( $type == 'purchase ') {
      echo '<td><span class="label label-info label-mini"> ';
   } else {
      echo '<td><span class="label label-success label-mini"> ';
   }
   echo $type
   echo '</span></td>';
?>

您可以根据您的类型添加条件,如下所示:

<tr>
<td><span class="label <?php if ($type == 'purchase') { echo 'label-info'; } elseif ($type == 'refund') { echo '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>


您可以根据您的类型添加条件,如下所示:

<tr>
<td><span class="label <?php if ($type == 'purchase') { echo 'label-info'; } elseif ($type == 'refund') { echo '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>


如果您的情况是在一个名为$txn_类型的变量中 试试这个

<td class="<?php echo ($txn_type == 'purchase')?("label label-info label-mini":($txn_type == 'Refund')?"label label-success label-mini":"")?>" >

如果您的病情处于一个称为$txn\u类型的变量中
试试这个

<td class="<?php echo ($txn_type == 'purchase')?("label label-info label-mini":($txn_type == 'Refund')?"label label-success label-mini":"")?>" >

谢谢您的支持。我已经试过了,但是我得到了这个错误。。。你能帮忙吗。错误:未定义变量:C:\wamp\www\Projects\CCDLB\edidelindex.php中的标签在调用之前是否包含php代码?排队?谢谢你的支持。我已经试过了,但是我得到了这个错误。。。你能帮忙吗。错误:未定义变量:C:\wamp\www\Projects\CCDLB\edidelindex.php中的标签在调用之前是否包含php代码?排队?谢谢,我也试过了。正如预期的那样,它工作得很好。谢谢,我也试过这个。它的工作正常。