【问题标题】:PHP while code errorPHP while 代码错误
【发布时间】:2018-04-28 04:47:18
【问题描述】:
<?php 
$host="localhost";
$user="root";
$pwd="";
$db="assigment";
$conn=mysqli_connect($host,$user,$pwd,$db);
 $query="SELECT * FROM 'tdata'";
 $result=mysqli_query($conn,$query);
 while ($row=mysqli_fetch($result)) {

  ?>
   <table class="table">
        <thead>
        <tr>
            <th>Full Name</th>
            <th>Email</th>
            <th>Birthday</th>
            <th>Gender</th>
            <th>Intrests</th>
            <th>Address</th>
            <th></th>
        </thead>
        </tr>
        <tbody>
        <?php echo "<tr><td>".$row[full_name]."</td></tr>";
         }
         ?>

        </tbody>
    </table>

错误# 致命错误:未捕获的错误:调用 C:\xampp\htdocs\gsoft\assigment\tabledb.php:9 中的未定义函数 mysqli_fetch() 堆栈跟踪:#0 {main} 在 C:\xampp\ 中抛出htdocs\gsoft\assigment\tabledb.php 第 9 行

【问题讨论】:

标签: php error-handling while-loop


【解决方案1】:

如果你想在没有索引的情况下获取,请使用mysqli_fetch_assoc()

或者

如果您想使用索引获取,请使用mysqli_fetch_array()

我认为你在这里做错了,因为你的表格标签在 while 循环内,你的 &lt;thead&gt; 也是。 我认为它应该在while循环之外。并且您的查询中有语法错误,并且您有一个额外的&lt;th&gt;

您的完整代码。

<?php 
$host="localhost";
$user="root";
$pwd="";
$db="assigment";
$conn=mysqli_connect($host,$user,$pwd,$db);
 $query="SELECT * FROM tdata ";
 $result=mysqli_query($conn,$query); ?>
 <table class="table">
        <thead>
        <tr>
            <th>Full Name</th>
            <th>Email</th>
            <th>Birthday</th>
            <th>Gender</th>
            <th>Intrests</th>
            <th>Address</th>
        </tr>
        </thead>

        <tbody>
 <?php while ($row=mysqli_fetch_assoc($result)) { ?>

        <tr>
            <td><?php echo $row['full_name']; ?></td>
            <td><?php echo $row['your table field name']; ?></td>
            <td><?php echo $row['your table field name']; ?></td>
            <td><?php echo $row['your table field name']; ?></td>
            <td><?php echo $row['your table field name']; ?></td>
            <td><?php echo $row['your table field name']; ?></td>
        </tr>
        <?php }
         ?>
        </tbody>
    </table>

【讨论】:

    【解决方案2】:

    使用mysqli_fetch_array函数代替mysqli_fetch

    【讨论】:

      【解决方案3】:

      使用 mysqli_fetch_array 代替 mysqli_fetch

      你的桌子也在循环内

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-04-07
        • 2016-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-09
        • 1970-01-01
        相关资源
        最近更新 更多