Mysql,删除具有多个值的行

时间:2013-02-28 13:30:56

标签: php mysql

image http://visedeg.no/images/4ewq24mr3r76uuhq9324.png

在图片上,您看到我的行具有相同的值。我只想给他们看一次。 行中的值是第9周中每笔钱的总和。

<? 
$result5 = mysql_query("SELECT * FROM Donering WHERE Uke=".$Uke."");

while ($row1 = mysql_fetch_array($result5)){
    $nick = $row1['nickid'];
    $result6 = mysql_query("SELECT * FROM Donering WHERE nickid=".$nick." and Uke=".$Uke."  ");

    echo "<table border='1'>
        <tr>
        <th>Brukernavn</th>
        <th>Kr</th>
        <th>Uke</th>
        </tr>";

    while ($row = mysql_fetch_array($result6))  {
        $sum2 = $sum2+$row['Penger'];
        $DittNick = $row['Nick'];
    }

    if ($sum2 >= 2500000000) {
        $Fargekode = "#00FF00";
    }
    else {
        $Fargekode = "#FF0000";
    }

    echo "<tr>";
    echo "<td>" . $DittNick . "</td>";
    echo "<td><font color='".$Fargekode."'>". number_format ($sum2 , 0, ',', '.'  ) . "   </font></td>";
    echo "<td>Uke ".$Uke."</td>";
    echo "</tr>";

    echo "</table>";

    $sum2 = NULL;
}?>

3 个答案:

答案 0 :(得分:2)

首先,mysql_*已被弃用。请查看我的答案的底部以获取更多相关信息。如果你不这样做,有一天你的代码将毫无用处。

对于您的实际查询,请尝试使用SELECT DISTINCT。这将拉出唯一的行。

  

Please, don't use mysql_* functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDOMySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial

答案 1 :(得分:0)

也许你正在寻找这个,移动桌子的标题,以及关闭时间

<?$result5 = mysql_query("SELECT * FROM Donering WHERE Uke=".$Uke."");

echo "<table border='1'>
<tr>
<th>Brukernavn</th>
<th>Kr</th>
<th>Uke</th>
</tr>";

while ($row1 = mysql_fetch_array($result5)){
$nick = $row1['nickid'];

$result6 = mysql_query("SELECT * FROM Donering WHERE nickid=".$nick." and Uke=".$Uke."  ");



while ($row = mysql_fetch_array($result6))  {


$sum2 = $sum2+$row['Penger'];

$DittNick = $row['Nick'];


}

if ($sum2 >= 2500000000) {
$Fargekode = "#00FF00";
}
 else {
$Fargekode = "#FF0000";
}

echo "<tr>";
echo "<td>" . $DittNick . "</td>";
echo "<td><font color='".$Fargekode."'>". number_format ($sum2 , 0, ',', '.'  ) . "    </font></td>";
 echo "<td>Uke ".$Uke."</td>";
 echo "</tr>";



  $sum2 = NULL;

  }

  echo "</table>";?>

答案 2 :(得分:0)

您可以尝试在MySQL字符串中使用DISTINCT选项