数字统计表PHP MYSQL

时间:2014-03-18 17:08:55

标签: php mysql

我现在有一张统计表。

但我想要的是:

1.|Team
2.|Team
3.|Team

在球队之前我没有数据。 我的表是按“Punten”排序的,因此不能与团队一起添加。它必须是td的静态

这是我的代码:

    <?php
        $table = "e2teams";
        $sql = "SELECT ID, Team, Punten, Gespeeld, Gewonnen, Verloren, Gelijk, DPV, DPT, DPV-DPT AS Verschil FROM e2teams ORDER BY Punten DESC, Verschil DESC, DPV DESC";
        $result = mysql_query($sql, $dbhandle);


        echo "<table class='opmaaktable'><tr><td class='styled-td'>Team</td><td class='styled-td2'>G</td><td class='styled-td2'>W</td><td class='styled-td2'>GL</td><td class='styled-td2'>V</td><td class='styled-td2'>P</td><td class='styled-td2'>DPV</td><td class='styled-td2'>DPT</td><td class='styled-td2'>Vers.</td></tr></table>";  


        if(mysql_num_rows($result) > 0){
            $team = array();
            while($row = mysql_fetch_array($result)) {

                echo "<table><tr><td class='styled-td'>";
                echo $row['Team']. '</td><td class="styled-td2">';
                echo $row['Gespeeld']. '</td><td class="styled-td2">';
                echo $row['Gewonnen']. '</td><td class="styled-td2">';
                echo $row['Gelijk']. '</td><td class="styled-td2">';
                echo $row['Verloren']. '</td><td class="styled-td2">';
                echo $row['Punten']. '</td><td class="styled-td2">';
                echo $row['DPV']. '</td><td class="styled-td2">';
                echo $row['DPT']. '</td><td class="styled-td2">';
                echo $row['Verschil']. '</td><td class="styled-td2">';
                echo "</td></tr></table>";
                $team = $row['Team'];
                }
        }

    ?>

这就是它的样子: enter image description here

希望你能帮忙!

1 个答案:

答案 0 :(得分:3)

我不确定我是否遗漏了某些东西 - 但为什么不只是宣布一个计数器并在循环中增加它?

$ctr = 1;
while($row = mysql_fetch_array($result)) {

    echo "<table><tr><td class='styled-td'>";
    echo "$ctr." . $row['Team']. '</td><td class="styled-td2">';
    ...
    $ctr++;
}