我是PHP的新手,我只是在使用它,因为我需要在网上发布我的一些FileMaker数据库。
我想要做的是在表格中有一个单元格,根据FileMaker数据库中名为“ReferralStatus”的字段更改颜色,该字段的值只有“红色”,“绿色”或“黄色”
我将如何使用PHP / HTML / CSS完成此操作?我在考虑使用if / else条件来检查状态并分配一个类但是如何将它应用于元素?
现在我正在使用foreach循环来生成表行和表数据列。
以下代码对我有用:
<?php
foreach($relatedRecords as $related_record) {
echo
'<tr>' .
'<td style="border: 1px solid black; padding: 3px; background: #cacaca;">' . $related_record->getField('ReferredLeadsToCustomerLogins::DateReceived') . '</td>' .
'<td style="border: 1px solid black; padding: 3px; background: #cacaca;">' . $related_record->getField('ReferredLeadsToCustomerLogins::FirstName') . '</td>' .
'<td style="border: 1px solid black; padding: 3px; background: #cacaca;">' . $related_record->getField('ReferredLeadsToCustomerLogins::LastName') . '</td>' .
'<td style="border: 1px solid black; padding: 3px; background: #cacaca;">' . $related_record->getField('ReferredLeadsToCustomerLogins::FullAddress') . '</td>' .
'<td style="border: 1px solid black; padding: 3px; background-color: '. $related_record->getField('ReferredLeadsToCustomerLogins::ReferralStatus') . ';">' . $related_record->getField('ReferredLeadsToCustomerLogins::ReferralStatus') . '</td>' .
'</tr>';
}
?>
答案 0 :(得分:0)
PHP / HTML:
xcodebuild
$ ReferralStatus是&#34; Green&#34;,&#34; Red&#34;或者&#34;黄色&#34;,这样该行将输出如下:
xctool
CSS:
<td class="<?php echo $ReferralStatus; ?>"> foo </td>
答案 1 :(得分:0)
HTML / PHP:
<?php
foreach($relatedRecords as $related_record) {
echo
'<tr>' .
'<td style="border: 1px solid black; padding: 3px; background: #cacaca;">' . $related_record->getField('ReferredLeadsToCustomerLogins::DateReceived') . '</td>' .
'<td style="border: 1px solid black; padding: 3px; background: #cacaca;">' . $related_record->getField('ReferredLeadsToCustomerLogins::FirstName') . '</td>' .
'<td style="border: 1px solid black; padding: 3px; background: #cacaca;">' . $related_record->getField('ReferredLeadsToCustomerLogins::LastName') . '</td>' .
'<td style="border: 1px solid black; padding: 3px; background: #cacaca;">' . $related_record->getField('ReferredLeadsToCustomerLogins::FullAddress') . '</td>' .
'<td style="border: 1px solid black; padding: 3px; background-color: '. $related_record->getField('ReferredLeadsToCustomerLogins::ReferralStatus') . ';">' . $related_record->getField('ReferredLeadsToCustomerLogins::ReferralStatus') . '</td>' .
'</tr>';
}
?>