提问者:小点点

缺少PHPmyAdmin行数据


我有一个页面来显示一个从PHPmyAdmin数据库中提取信息的表,但是最新的数据行似乎总是丢失的,尽管表中有一行数据(只是空的)。如果我添加另一行,它会使前面的缺失行出现,但最新的一个是空的-非常恼人,我只是不明白为什么会发生这种情况!

查询以拉取信息:

$query = "SELECT * FROM users";
   $result = $db -> query ($query);
   $num = mysqli_num_rows($result);
   $row = $result->fetch_assoc();

显示表:


  <table class="styled-table" >
    <h2>All Users</h2>
      <thead>

          <tr>
              <th>User ID</th>
              <th>Username</th>
              <th>Email</th>
              <th>Type</th>
              <th>Update</th>
          </tr>
      </thead>

      <tbody>
        <?php
              for ($i=0; $i < $num; $i++)
              { $row = $result->fetch_assoc(); ?>
          <tr class="active-row">

              <td><?php echo $row["userID"];?></td>
              <td><?php echo $row["username"];?></td>
              <td><?php echo $row["email"];?></td>
              <td><?php echo $row["type"];?></td>
              <td><a href = "full.php?id=<?php echo $row['userID'];?>">Edit</a></td>

          </tr>
<?php }?>

CSS(不确定这是否会影响它)

.styled-table {
        border-collapse: collapse;
        margin: 25px 0;
        font-size: 0.9em;
        font-family: sans-serif;
        min-width: 900px;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
        margin-left: auto;
  margin-right: auto;

    }
    .styled-table thead tr {
    background-color: #009879;
    color: #ffffff;
    text-align: center;
}
.styled-table th,
.styled-table td {
    padding: 12px 15px;
    text-align: center;
}

.styled-table tbody tr {
    border-bottom: 1px solid #dddddd;
}

.styled-table tbody tr:nth-of-type(even) {
    background-color: #f3f3f3;
}

.styled-table tbody tr:last-of-type {
    border-bottom: 2px solid #009879;
}
.styled-table tbody tr.active-row {
    font-weight: bold;
    color: #009879;
}

共1个答案

匿名用户

必须删除$num=mysqli_num_rows($result);后面的$row=$result->fetch_assoc();。此调用将获取第一行,并且它将被for循环中的fetch_assoc()覆盖。