简体   繁体   English

数据库信息未从我的循环中显示

[英]Database info not showing from my loop

I new to php and learning and need some advice on shoing my database info within a loop which includes html, My page is blank so am wondering why my php isnt valid: 我是php的新手,学习并且需要一些建议来将数据库信息推送到包含html的循环中,我的页面为空白,所以我想知道为什么我的php是无效的:

<?php include 'incudes/connect_db.php'; ?>

    <div class="topbar">
        <div class="topbarblock1">Dashboard</div>
        <div class="topbarblock2">Username</div>
    </div>

    <br><br>

    <div class="middle">
        <div class="middleblock1">Dashboard</div>
        <div class="middleblock2">
            <div class="container">
            <?php
            $result = mysqli_query($con,"SELECT * FROM users");
            while($row = mysqli_fetch_array($result)) {
            ?>  
                <h2>
                    User Management
                    <hr />
                </h2>
            </div>
            <div class="containermain">
                <table>
                    <tr>
                        <th class="th1">User Id</th>
                        <th class="th2">Username</th>
                        <th class="th3">Email Address</th>
                        <th class="th4">Details</th>
                    </tr>
                    <tr>
                        <td class="td1">#</td>
                        <td class="td2"><?php echo $row['username']; ?></td>
                        <td class="td3"><?php $row['email']; ?></td>
                        <th class="td4">Edit</th>
                    </tr>                   
                </table>
            </div>
        </div>
    </div>

<?php   
}
?>

I'm not looking for a straight out answer I am looking for some advice on how this should be laid out and learn best practices. 我不是在寻找一个直接的答案,而是在寻找一些有关如何布局和学习最佳实践的建议。

Change the line that says 换行说

<td class="td3"><?php $row['email']; ?></td>

to

<td class="td3"><?php echo $row['email']; ?></td>

PHP will try to interpret the variable as some sort of command/statement otherwise and subsequently fail. PHP将尝试将变量解释为某种命令/语句,否则将失败。

Also rethink where you wrap the loop as I previously mentioned, or else your HTML is going to end up wonky (you'll see this after you've fixed the code.) 还要重新思考您如前所述在哪里包装循环,否则您的HTML最终将变得怪异(固定代码后,您将看到此信息。)

You should also program by using error_reporting(E_ALL); 您还应该使用error_reporting(E_ALL);编程error_reporting(E_ALL); at the start of your code so you can fix simple mistakes on your own 在代码的开头,因此您可以自行修复简单的错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM