MySQL没有拉出所有行 [英] MySQL not pulling all rows

查看:27
本文介绍了MySQL没有拉出所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,第一次使用 stackoverflow.

Hey guys, first time using stackoverflow.

你们能帮我调试吗?

问题来了,这个查询是从我的数据库中选择所有行,由于某种原因,它只输出了第一行两次.

Heres the problem, this query is selecting all of the rows from my database, its only outputting the first one twice for some reason.

  $top10_query = "SELECT * FROM kicks";
  $result = mysqli_query($cxn, $top10_query) or die("Couldn't execute query.");
  $row = mysqli_fetch_assoc($result);

  $rating = $row['rating'];
  $description = $row['description'];
  $completed = $row['completed'];
  $userid = $row['userid'];
  $posted = $row['posted'];

  while($row = mysqli_fetch_assoc($result)) {
   echo "<tr>";
    echo "<td class='rating'>" . $rating . "</td>";
    echo "<td class='description'>" . $description . " </td>";
    echo "<td class='completed_" . $completed . "'>" . $completed  . "</td>";
    echo "<td class='author'>";
     echo "Posted by: <a href='profile?userid=" . $userid . "'>" . $userid . "</a><br />";
     echo "on "; echo $posted;
    echo "</td>";
   echo "</tr>";
  }

推荐答案

您正在循环遍历行集,但从未多次检索其值.您从第一行中提取了所有值,并将它们缓存在此处:

You are looping over the rowset, but never retrieving its value more than once. You pulled all of the values out of the first row, and cached them here:

$rating = $row['rating'];
$description = $row['description'];
$completed = $row['completed'];
$userid = $row['userid'];
$posted = $row['posted'];

将此代码移动到循环中,并删除第一个提取.

Move this code into the loop, and remove the first fetch.

这篇关于MySQL没有拉出所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆