【问题标题】:PHP MySQL only displays Blank TablePHP MySQL 只显示空白表
【发布时间】:2019-03-28 08:34:10
【问题描述】:

美好的一天!我在显示表中的数据时遇到问题。我已经输入了 6 个数据,它将显示我的 $i++ 中有多少个基数,但它不显示用户名、全名和 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>

【问题讨论】:

    标签: php mysql mysqli


    【解决方案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>
    

    【讨论】:

      【解决方案2】:
      $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,根据您的表格进行相应调整,希望对您有所帮助!

      【讨论】:

        【解决方案3】:

        首先,你错过了end&lt;/tr&gt;,其次你真的必须使用变量i并增加它吗?在哪里可以回显所有 ID?以及为什么你的右括号后面有分号。最后,你应该把 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))
        {
        ?>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-05-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多