gpt4 book ai didi

php - MySQL-第一行被跳过

转载 作者:行者123 更新时间:2023-11-29 04:24:09 25 4
gpt4 key购买 nike

我有一个 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) 没有被打印出来。我在这里做错了什么?

最佳答案

在你的代码中

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

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

mysql_fetch_arraywhile 循环之前。

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

关于php - MySQL-第一行被跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15322151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com