0

image
(source: visedeg.no)

On the picture you see i have rows with same value. I want to show them only one time. The values in the row is a sum of every money in week 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;
}?>
2
  • Use Group By with your query Commented Feb 28, 2013 at 13:36
  • Of course :) how could i be so stupid. Tnx ! Commented Feb 28, 2013 at 21:12

3 Answers 3

2

First of all, mysql_* is being deprecated. Look at the bottom of my answer for more information on that. If you don't, some day your code will be useless.

For you actual query, try using SELECT DISTINCT. This will pull unique rows.

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you are looking for this, move the header of the table, and the close out of the while

<?$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>";?>

5 Comments

Tnx for fast replay. But then this happend: visedeg.no/images/lewl5e0yk5ciw89jfif1.png
I misunderstand the question, but maybe this will help too (thats why I didnt deleted it)
Did you move the </table> out of the while?
That was the html? Do you mean CSS?
The html result of the php. Right click->show source in the browser
0

You can try to use DISTINCT option in your MySQL string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.