1

データベースから結果を取得し、ページに表示しようとしました。しかし、アライメントが正しくありません。どうすれば修正できますか?

ビュー内のコード

<?php

        echo "<table align='center'>";

        echo "<tr>";
        echo "<td>  Language ID:  </td>";
        echo "</tr>";

        echo "<tr>";
        echo "<td> Language Name:  </td>";
        echo "</tr>";

        echo "<tr>";
        echo "<td> Date Posted :  </td>";
        echo "</tr>";

        if ($query == true) {
            foreach ($query as $row) {

                echo "<tr>";
                echo "<td>" . $row -> pk_bint_language_id . "</td>";
                echo "<td>" . $row -> vchr_language_name . "</td>";
                echo "<td>" . $row -> bint_language_level . "</td>";
                echo "<td>" . $row -> dat_updated_date . "</td>";

                echo "</tr>";

            }

        }

        echo "</table>";
        ?>

出力:

ここに画像の説明を入力

4

3 に答える 3

1

You want to display four rows within the foreach loop, however you have only three in the header section. From what I can see you are missing Language level /added to the example/

 echo "<table align='center'>
          <tr>
            <td> Language ID:  </td>
            <td> Language Name:  </td>
            <td> Language Level:  </td>
            <td> Date Posted :  </td>
          </tr>";

    if ($query == true) {
        foreach ($query as $row) {

            echo "<tr>";
            echo "<td>" . $row -> pk_bint_language_id . "</td>";
            echo "<td>" . $row -> vchr_language_name . "</td>";
            echo "<td>" . $row -> bint_language_level . "</td>";
            echo "<td>" . $row -> dat_updated_date . "</td>";

            echo "</tr>";

        }

    }

    echo "</table>";
于 2013-04-20T12:51:31.267 に答える
0

thの代わりにテーブル ヘッダーを使用する必要がありtdます。少なくともそれはより適切な方法です。

<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

w3school http://www.w3schools.com/html/html_tables.aspで確認できます。

@bborisovsの答えは正しいです。ただし、4 つではなく 3 つの td を使用する場合は、次のようにすることもできます

<td colspan="2"> //meainng this single 'td' with take two 'td' place
于 2013-04-21T01:03:23.497 に答える
0

You seem to have 3 <td>s in the first table row (<tr>) with the static "Language ID:" and such, but you have 4 <td>s inside the foreach() loop. It seems like you are missing the "Language level" from the static <td>s.

I would recommend to use the <thead> and <tbody> tags as well.

于 2013-04-20T12:51:39.907 に答える