dongshi1934 2018-04-26 15:21
浏览 86
已采纳

表格没有正确填充PHP HTML MYSQL

I am trying to add records from my database to a table as a list of links that takes the user to a more details page about vendors they can view. But only the first record is being put in the table where as the rest are appearing as a jumbled up mess outside the table at the bottom of it.

Can anyone see what I've done wrong with my table echos?

<?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>

enter image description here

  • 写回答

2条回答 默认 最新

  • doubomudichen0832 2018-04-26 15:28
    关注

    Take echo "</table>"; out of the while loop and put it after the closing bracket.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧