我需要根据状态设置表格。例如已完成=绿色& 待定=橙色
PHP代码。它从Mysql中提取数据
$query = mysql_query("SELECT * FROM cashouts WHERE uid = ".$Auth->getLoggedId()." ORDER BY id DESC LIMIT $offset, $showPerPage");
while($row = mysql_fetch_object($query))
{
$username = $row->username;
$amount = $row->amount;
$status = $row->status;
$method = $row->method;
$priority = $row->priority;
if($status == 'Complete' && !empty($row->payment_date))
$date = date("d M, Y",strtotime($row->payment_date));
else
$date = date("d M, Y",strtotime($row->request_date));
$payments[] = array('date' => $date, 'amount' => $amount, 'method' => $method, 'status' => $status, 'cycle' => $priority);
}
我的tpl / html文件代码
<tbody>
{if $payments ne ""}
{foreach item=payment from=$payments}
<tr>
<td>{$payment.date}</td>
<td>${$payment.amount}</td>
<td>{$payment.method}</td>
<td>{$payment.status}</td>
<td>{$payment.cycle}</span></td>
</tr>
{/foreach}
{/if}
</tbody>
我需要的是如果status = Completed then
<td style="color: Green;">{$payment.status}</td>
否则,如果status = Pending then
<td style="color: Orange;">{$payment.status}</td>
答案 0 :(得分:0)
在SQL select语句中添加CASE。
CASE status
WHEN 'Completed' THEN 'Green'
WHEN 'Pending' THEN 'Orange'
ELSE ''
End As color
$color = $row->color
<td style="color: {$payment.color};">{$payment.status}</td>