PHP MySQL仅显示空白表

时间:2018-10-24 02:36:56

标签: php mysql mysqli

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

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>

3 个答案:

答案 0 :(得分:1)

您忘记了回应结果。

更改

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

答案 1 :(得分:0)

首先,您错过了结尾</tr>,第二,您真的必须使用变量i并将其递增吗?在哪里可以回显所有ID?以及右括号后为何要使用分号。最后,您应该在变量uresult中加入echo希望对您有所帮助

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

答案 2 :(得分:0)

$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,根据您的表进行相应的调整,希望对您有所帮助!