有条件地格式化HTML表值

I have a custom web-app, getting data from a FileMaker database and spitting it out XML -> PHP -> HTML.

I'm currently generating a table in a big FOR loop and echoing out the results like so:

echo '
<tr>
    <td><strong>Qty Approved</strong></td>
    <td><strong>' . $record['qty1 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty2 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty3 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty4 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty5 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty6 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty7 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty8 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty9 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty10 approved'][0] . '</strong></td>
    <td><strong>' . $record['qty11 approved'][0] . '</strong></td>
    <td>'. $approved_string . '</td>
</tr>

';

I want to conditionally highlight some of the values in the table (which is what I'm doing with that $approved_string) whereby if e.g. the qty5 approved value > 0 then make it red, else make it green.

I understand how to reformat the table to properly use CSS, but what I don't know is whether or not to pre-calculate the values before echoing the table like with that $approved_string OR if I can/should be placing an if statement within my echo statement?

Repeated tasks -> make a function:

function highlight_record_value($record, $qty_index) {
    $value = $record['qty'.$qty_index.' approved'][0];
    if ($qty_index == 5) {
        if ($value > 0)
            $color = 'red';
        else
            $color = 'green';

        return sprintf('<span style="color: %s;">%s</span>', $color, $value);
    }

    //anything else you want

    return $value;
}

echo '
<tr>
    <td><strong>Qty Approved</strong></td>
    <td><strong>' . highlight_record_value($record, 1) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 2) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 3) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 4) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 5) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 6) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 7) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 8) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 9) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 10) . '</strong></td>
    <td><strong>' . highlight_record_value($record, 11) . '</strong></td>
</tr>

';