有条件地格式化 HTML 表值
我有一个自定义 Web 应用程序,从 FileMaker 数据库获取数据并将其吐出 XML -> PHP-> HTML。
我目前正在一个大的 FOR 循环中生成一个表,并回显结果,如下所示:
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>
';
我想有条件地突出显示表中的一些值(这就是我对 $approved_string 所做的事情),例如,如果 qty5认可值> 0则将其设为红色,否则将其设为绿色。
我了解如何重新格式化表格以正确使用CSS,但我不知道是否要在回显表格之前预先计算值,就像 $approved_string 或者我是否可以/应该在其中放置 if 语句我的回声声明?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重复任务->做一个函数:
Repeated tasks -> make a function: