我有一个问题,我不确定它是否可能,这是我的带有mysql数据的php页面
// connect to the database
include("connect-db.php");
$color ="#ffffff";
$color3 ="#99C";
$fontsize ="2";
$color4 ="#6CC";
$id = $rows['id'];
echo "<center><table border='2' cellspacing='0' cellpadding='2' class='sortable' bordercolor='#6699FF' bordercolor='#6699FF' width='100%'>
<tr>
<th >CitizenID</th>
<th>Worked</th>
<th>Military Rank Points</th>
<th>Supply Amount</th>
<th>Supplied</th>
<th>eDay</th>
</tr>";
$results = mysqli_query($con,"SELECT * FROM `supplies` ORDER BY citname ASC, eday ASC");
while($row = mysqli_fetch_array($results))
{
if($row['citname'] <> $current_citizenship){
$current_citizenship = $row['citname'];
echo "<tr>
<td colspan='7' align='center' bgcolor='" . $color4 . "'><strong><a name='" . $row['citname'] . "' id='" . $row['citname'] . "'>" . $row['citname'] . "</a></strong></td>
</tr>";
}
if ($row['wassupplied'] == Yes){
$color9 = "green"; } else
$color9 = "red";
if ($row['worked'] == Yes){
$color8 = "green"; } else
$color8 = "red";
if ($row['supplyamount'] < 11){
$color7 = "green"; } else
$color7 = "red";
if ($row['supplyamount'] == 10){
$color7 = "yellow"; } else
$color7 = "red";
if ($row['supplyamount'] > 20){
$color7 = "#FC0"; }
echo "<tr>";
echo "<td align='center' valign='middle' width='75px' bgcolor='" . $color3 . "'><font size='" . $fontsize . "'><a href='http://www.erepublik.com/en/citizen/profile/" . $row['citid'] . "' target='_blank'>".$row['citid']."</a></td>";
echo "<td align='left' valign='middle' bgcolor='" . $color8 . "'><font size='" . $fontsize . "'>" . $row['worked'] . "</td>";
echo "<td align='left' valign='middle' bgcolor='" . $color6 . "'><font size='" . $fontsize . "'>" . $row['rankpoints'] . "</td>";
echo "<td align='left' valign='middle' bgcolor='" . $color7 . "'><font size='" . $fontsize . "'>" . $row['supplyamount'] . "</td>";
echo "<td align='left' valign='middle' bgcolor='" . $color9 . "'><font size='" . $fontsize . "'>" . $row['wassupplied'] . "</td>";
echo "<td align='left' valign='middle' bgcolor='" . $color . "'><font size='" . $fontsize . "'>" . $row['eday'] . "</td>";
echo "</tr>";
}
mysqli_close($con);
我想设置一个像我所做的变量
if ($row['worked'] == Yes){
$color8 = "green"; } else
$color8 = "red";
代表$row['rankpoints']
这是我的问题
我的mysqli查询循环到按名称分组,每个citname都有每天显示的排名
if ($row['rankpoints'] == $row['rankpoints'] ){
$color6 = "red"; } else
$color6 = "grenn";
现在我的问题是我需要它与以前的eday字段进行比较 因此,如果2个rankpoints =相同的$ color6那么那些将变为红色
我希望这是理解
我想做的是以下
答案 0 :(得分:2)
这是一个简单的组更改循环,第一步:添加初始化程序
...
$lastrankpoints="ThisIsWrong\nThisIsWrong"; //or whatever surely is NOT a ranking
while($row = mysqli_fetch_array($results))
...
第二步:添加组更改
...
if ($row['supplyamount'] > 20){
$color7 = "#FC0"; }
if ($row['rankpoints'] === $lastrankpoints ){
$color6 = "red"; } else
$color6 = "green";
$lastrankpoints=$row['rankpoints'];
...