0

我从我的服务器获取数据并希望它们显示如下:

http://gyazo.com/3ed9349af4a0c3eb9fe9492b74104526

相反,会发生这种情况:

http://gyazo.com/2c7960ff62c35723b444545476e1d99c

我使用 PHP 作为值:

<table border="0" cellspacing="0" cellpadding="0">
        <tr> 
            <td>
                Player Name
            </td>
            <td >
                PK Level
            </td>
            <td>
                Kills
            </td>
            <td>
                Experience
            </td>           
        </tr>

        <tr>
            <td >
                    <?php
                        $result = mysql_query("SELECT * FROM high ORDER BY Runecraftlvl DESC LIMIT 20");

                        while($row = mysql_fetch_array($result))
                          {
                          echo $row['Runecraftlvl'];
                          echo "<br />";
                          }
                    ?>
            </td>
            <td>
                    <?php
                        $result = mysql_query("SELECT * FROM high ORDER BY Runecraftlvl DESC LIMIT 20");

                        while($row = mysql_fetch_array($result))
                          {
                          echo $row['Runecraftlvl'];
                          echo "<br />";
                          }
                    ?>
            </td>
            <td>
                    <?php
                        $result = mysql_query("SELECT * FROM high ORDER BY Runecraftlvl DESC LIMIT 20");

                        while($row = mysql_fetch_array($result))
                          {
                          echo $row['Runecraftlvl'];
                          echo "<br />";
                          }
                    ?>
            </td>
            <td>
                    <?php
                        $result = mysql_query("SELECT * FROM high ORDER BY Runecraftlvl DESC LIMIT 20");

                        while($row = mysql_fetch_array($result))
                          {
                          echo $row['Runecraftlvl'];
                          echo "<br />";
                          }
                    ?>
            </td>           
        </tr>

    </table>

为什么会这样?我怎样才能让数据放在单独的行上,每行 4 个数据?

4

1 回答 1

1

Before giving away any code, I'll give you a few hints.

Since you're not getting my point... You should add a counter yourself, and check whether or not you have to close the row.

But... Because you want 4 values in one cell, you will have to write them to temporary variables. You would need 4 variables: player_name, pk_level, kills and experience. When you've read out every 4th row of your query result, write them to the table.

($counter % 4) == 0 will be the main if-clause in your code. This will be true whenever the remainder of the division $counter / 4 is 0.

Also remember: you only need to perform your query once.

Give it a try first, and let us know what you come up with.

于 2013-01-27T23:35:40.753 回答