MySQL-第一行被跳过

问题描述:

我有一个MySQL表看起来这一点 -MySQL-第一行被跳过

enter image description here

当我尝试使用下面的代码

<?php 
include_once("connect.php"); 
$sql = "SELECT * FROM scores"; 
$query = mysql_query($sql) or die("systemResult=Error"); 
$counter = mysql_num_rows($query); 

if($counter>0) 
{ 
    print("systemResult=Success<br>"); 

    while($data=mysql_fetch_array($query)) 
    { 
     $athleteName = $data["athleteName"]; 
     print "&athleteName=" . $athleteName; 
     print "<br>"; 
    } 
} 
else 
{ 
    print("systemResult=Error"); 
} 
?> 

的精确副本打印所有行代码 - http://pastebin.com/00WFdnrt

我得到以下输出

systemResult=Success 
&athleteName=Guest-73 
&athleteName=Guest-71 
&athleteName=Guest-24 
&athleteName=Guest-67 
&athleteName=Guest-37 
&athleteName=Guest-23 
&athleteName=Guest-91 
&athleteName=ankur 
&athleteName=Guest-41 
&athleteName=Guest-38 
&athleteName=Guest-72 
&athleteName=Guest-25 
&athleteName=Guest-36 
&athleteName=Guest-17 

Click here for the live version

正如你可以看到第一行(ID:1,atheleteName:ANKUR)并没有被打印。我在这里做错了什么?

+1

请注意,'mysql_ *'函数已被弃用(请参阅[red box](http://php.net/mysql_query))。 – 2013-03-10 12:22:45

+2

我是唯一一个在访问他的网站时从病毒扫描程序得到警告的人吗? ' 网页:http:// mathlympics.cu.cc/php/getData.php' --- '访问网页被ESET NOD32 Antivirus阻止。该网页位于具有潜在危险内容的网站列表中。' – w00 2013-03-10 12:25:16

+0

为什么ankur的时间戳为0? – DevelopmentIsMyPassion 2013-03-10 12:26:09

在您的代码

  if($counter>0) 
      { 
        print("systemResult=Success<br>"); 
        $array = mysql_fetch_array($query); 

        while($data=mysql_fetch_array($query)) 
        { 

你有mysql_fetch_array之前while循环。

只要删除该行,您也将获得第一条记录。

+0

Marcel,我看到与你不同的代码吗?我没有看到那行 – Sebas 2013-03-10 12:37:36

+0

@ Sebas:在Pastebin中,OP提供了:http://pastebin.com/00WFdnrt(请参阅他的评论)。 – 2013-03-10 12:38:07

+1

哦,我不能相信, – Sebas 2013-03-10 12:38:36

&athleteName=Guest-91 
&athleteName=ankur 

行上市之后,你需要在查询中使用ORDER BY ID ASC

$sql = "SELECT * FROM scores ORDER BY ID ASC"; 

更新:根据公布的代码,mysql_fetch_array叫了两声:

 if($counter>0) 
     { 
       print("systemResult=Success<br>"); 

       $array = mysql_fetch_array($query); 
       while($data=mysql_fetch_array($query)) 
       { 

**只要删除第一个($array = mysql_fetch_array($query);

+0

@Akam更新了图像。正如你可以看到我有两个ankur行,但只有一个正在输出 – 2013-03-10 12:35:47

在这个文件中,你是指

@Akam是相当多 - pastebin.com/00WFdnrt的精确副本 - 安高尔·沙玛2分钟前

有一条线没有。 9:

$array = mysql_fetch_array($query); 

    while($data=mysql_fetch_array($query)) 

这会导致第一条记录丢失。

你没有在你的问题中写这个。