php mysql只显示空白表

bjp0bcyl  于 2021-06-18  发布在  Mysql
关注(0)|答案(3)|浏览(317)

很好的一天!我在显示表中的数据时遇到问题。我已经输入了6个数据,它将显示多少基地从我的$i++但它没有显示用户名,全名和udate。我真的很感激,谢谢你!表显示这里是我的代码:

table class="table table-striped table-sm">
  <thead>
    <tr>
      <th>No</th>
      <th>User No</th>
      <th>User Name</th>
      <th>Date Registered</th>
    </tr>
  </thead>
  <tbody>

    <?php
      $i=0;
      $uquery= mysqli_query($conn, "SELECT * FROM users");
      while ($uresult=mysqli_fetch_array($uquery)){

      $i++;  
    ?>
      <tr>
        <td><?php echo $i;?></td>
        <td><?php $uresult ['userno'];?></td>
        <td><?php $uresult ['fullname'];?></td>
        <td><?php $uresult ['udate'];?></td>

    <?php }; ?> 
  </tbody>
</table>
ycl3bljg

ycl3bljg1#

你忘了回显你的结果。
改变

<td><?php $uresult ['userno'];?></td>
<td><?php $uresult ['fullname'];?></td>
<td><?php $uresult ['udate'];?></td>

<td><?php echo $uresult ['userno'];?></td>
<td><?php echo $uresult ['fullname'];?></td>
<td><?php echo $uresult ['udate'];?></td>

<td><?= $uresult ['userno'];?></td>
<td><?= $uresult ['fullname'];?></td>
<td><?= $uresult ['udate'];?></td>
fcy6dtqo

fcy6dtqo2#

$sql = "SELECT userno, fullname, udate FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
            echo "<br> userno: ". $row["userno"]. " - Full Name: ". $row["fullname"]. " - udate: " . $row["udate"] . "<br>";
}
} else {
    echo "0 results";
}
//Don't Forget To:
$conn->close();

这将是你的php,调整它相应的表,希望这有帮助!

4smxwvx5

4smxwvx53#

首先,你错过了终点 </tr> ,第二,你真的必须使用变量i并增加它吗?在那里你可以回显所有的身份证?最后,你应该在变量中加上echo uresult 希望这对你有帮助

<table class="table table-striped table-sm">
<thead>
<tr>
  <th>No</th>
  <th>User No</th>
  <th>User Name</th>
  <th>Date Registered</th>
</tr>
</thead>
<tbody>

<?php
  $uquery= mysqli_query($conn, "SELECT * FROM users");
  while ($uresult=mysqli_fetch_array($uquery)){
?>
  <tr>
    <td><?php echo $uresult ['id'];?></td>
    <td><?php echo $uresult ['userno'];?></td>
    <td><?php echo $uresult ['fullname'];?></td>
    <td><?php echo $uresult ['udate'];?></td>
  </tr>
<?php } ?> 
</tbody>
</table>

and also you can write it, in this way:
and echo variable `i` if you want to see the count of it.
<?php
  $uquery= "SELECT * from users";
  $viewquery = mysqli_query($con,$uquery);
  while($uresult = mysqli_fetch_assoc($viewquery))
{
?>

相关问题