我有一个页面,它从数据库中获取信息并将其显示在表格中。它确实有效,但它非常麻烦。
//Table header here
echo "<tr><td>".$teamname."</td>";
//For Gameweek 7
if ($gw7 == "")
{
//The team has no game - highlight the cell in red
echo "<td align='center' style='background: #FF0000'>";
}
elseif (strpos($gw7,'/') !== false)
{
//The team has 2 games this week - highlight it in green
echo "<td align='center' style='background: #00FF00'>";
}
else
{
//this means the team has a single game this week - normal cell.
echo "<td align='center'>";
}
echo $gw7."</td>";
echo "</tr>";
//for gameweek 8 to 36, the above for loop is just repeated (mostly copy/pasted)
//Table footer here
有更清洁的方法吗?我不喜欢多次复制/粘贴相同的代码。
比赛周称为$gw7
、$gw8
、等$gw9
,$gw10
并以文本格式包含球队面临的对手。$gw7 中的 7 代表本赛季的第 7 套比赛。它们被分组到游戏周中。如果不清楚,请告诉我。