简体   繁体   English

mysql没有返回所有行

[英]mysql is not returning all the rows

This is the query I have: 这是我的查询:

  $sqlw = "SELECT * FROM coverages where user_id='3828' ORDER BY sp_id ASC";
  $resultw = mysql_query($sqlw);    
  $roww    = mysql_fetch_array($resultw);
  while ($roww = mysql_fetch_array($resultw)) {

  echo $roww['sp_id']."<br>";

      }
  echo "TOTAL:".mysql_num_rows($resultw)."<br>";

As you can see its very basic the results show : TOTAL:29 But when I count the list of the items returned back its only 28. I ran the query on phpmyadmin it shows a total of 29 rows, I did count them and they are 29. 如您所见,它的结果非常基本:TOTAL:29但是当我计算返回的项目列表时,它只有28个。我在phpmyadmin上运行了查询,它显示总共29行,我确实对它们进行了计数,它们是29。

I ran different other simple queries and it always does the same thing: one row is missing. 我运行了其他简单查询,但它总是做同样的事情:缺少一行。 This could be trivial maybe I am missing something or maybe its server related? 这可能是微不足道的,也许我缺少某些东西,或者它与服务器有关? any help/ideas would be greatly appreciated. 任何帮助/想法将不胜感激。 Thank you 谢谢

在循环处理一行之前,您对mysql_fetch_array()调用。

You have a classic off-by-one error. 您有一个经典的一次性错误。

There is an extra $roww = mysql_fetch_array($resultw); 还有一个额外的$roww = mysql_fetch_array($resultw); before your loop starts. 在循环开始之前。 This means you're throwing away the first row. 这意味着您要丢掉第一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM