表未正确填充php html mysql

q5lcpyga  于 2021-06-23  发布在  Mysql
关注(0)|答案(2)|浏览(292)

我正在尝试将数据库中的记录添加到一个表中,作为一个链接列表,该列表将用户带到有关他们可以查看的供应商的更多详细信息页面。但是只有第一条记录被放进了表中,而其他的记录在表的底部,看起来像是一团乱七八糟的东西。
有人能看到我的table回声有什么问题吗?

<?php
session_start();

$link = mysqli_connect("localhost", "root", "root") or die(mysqli_error($db));
mysqli_select_db($link, "keepers")
or die(mysqli_error($link));

// Check connection
if($link === false)
{
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
<html>
<head>
    <title>Beekeeper</title>
    <meta name="author" content="Nigel Kennington">
    <meta name="description" content="Find local honey near you">
    <meta name="keywords" content="honey, bees, bee, local">
    <link href="bees.css" type="text/css" rel="stylesheet">
</head>
<body>

    <div id="linkbar">
        <table height="140px" ID="Table1">
            <tr>
                <td valign="bottom"><a href="index.php">Home</a>&nbsp;&nbsp;|</td>
                <td valign="bottom"><a href="about.html">About</a>&nbsp;&nbsp;|</td>
                <td valign="bottom"><a href="contact.html">Contact</a></td>
            </tr>
        </table>
    </div>

    <div id="bulk">
        <table width="100%" border="0" cellpadding="0" cellspacing="0" ID="Table1">
            <tr id="spacer">
                <td class="leftnav" align="right" valign="top" nowrap width="120px">
                    <h5>Find Honey from:</h5>
                    <p><a href="HaL.php">Highlands and Islands</a></p>
                    <p><a href="NES.php">North Eastern Scotland</a></p>
                    <p><a href="ES.php">Eastern Scotland</a></p>
                    <p><a href="SWS.php">South Western Scotland</a>
                    <h5>List your produce:</h5>
                    <p><a href="keeperlogin.php">Keepers Page</a></p>
                </td>
                <td>
                    <?php
                        $sql = "SELECT * FROM keepers WHERE area = 'HaI'";
                        $result = mysqli_query($link, $sql);

                                echo "<table width=100% border='1'>
                                <tr>
                                <th><p class='success'>Shop Name</p></th>
                                <th><p class='success'>Shop Email</p></th>
                                <th><p class='success'>Town</p></th>
                                <th><p class='success'>Phone Number</p></th>
                                <th><p class='success'>Mobile Number</p></th>
                                </tr>";

                            while($row = mysqli_fetch_assoc($result))
                            {
                                $id = $row['ID'];

                                echo "$id";
                                echo "<tr>";
                                echo "<td> <a href='viewdetails.php?id=$id'>" . $row['shop_name'] . "</a> </td>";
                                echo "<td> <a href='viewdetails.php?id=$id'>" . $row['shop_email'] .  "</a> </td>";
                                echo "<td> <a href='viewdetails.php?id=$id'>" . $row['town'] . "</a> </td>";
                                echo "<td> <a href='viewdetails.php?id=$id'>" . $row['phone_number'] . "</a> </td>";
                                echo "<td> <a href='viewdetails.php?id=$id'>" . $row['mobile_number'] . "</a> </td>";
                                echo "</tr>";

                                echo "</table>";
                            }

                    ?>
                </td>
            </tr>
        </table>

    </div>

    <div id="footer">
        © 2008 beekeeper.com | <A href="privacy.html">Privacy Policy</A> | 
        <A href="terms.html">Terms of Use</A>
    </div>

</body>

kuarbcqp

kuarbcqp1#

采取 echo "</table>"; 退出while循环并将其放在闭合支架之后。

bttbmeg0

bttbmeg02#

您将在while循环结束之前关闭table标记 echo "</table>"; 把它从循环中移开。。。。

相关问题