表内条件[关闭]

How to make a condition inside table in php with foreach?

foreach($query->result_array() as $dtrpt)
        {
            $cRet .='
            <tr>
                <td align="center" style="font-size:12px;">'.$dtrpt['tgl_bukti'].'</td>
                <td align="center" style="font-size:12px;">'.$dtrpt['no_kas'].'</td>
                <td align="center" style="font-size:12px;">'.$dtrpt['tipe'].'</td>
                <td align="center" style="font-size:12px;">'.number_format($dtrpt['nilai'], 2, ',', '.').'</td>
                <td align="center" style="font-size:12px;">'.number_format($dtrpt['nilai'], 2, ',', '.').'</td>
                <td align="center" style="font-size:12px;">'.number_format($dtrpt['nilai'], 2, ',', '.').'</td>
            </tr>

            ';
}

Do you mean something like the following?

echo '<td>' . ($data['temperature'] < 5 ? 'Cold' : 'Warm') . '</td>';

The above uses the ternary operator as a contracted if/else within a table cell.