简体   繁体   中英

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.

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); before your loop starts. This means you're throwing away the first row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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