php - 为什么这段代码会错过第一个条目?

标签 php mysql mysqli phpmyadmin

好的,我的代码有一个小问题:它没有得到第一个结果? 例如:禁令表可能如下所示: [http://i.stack.imgur.com/dYuCd.png][1] 但回显的数据将错过第一行,即带有 RDMx3 和 Evade 原因且没有名称的行。

例如:这里直接来自 SourceBans: http://i.stack.imgur.com/Snxzv.png

这是使用以下代码的版本: http://i.stack.imgur.com/eCexb.png

请注意,第一个禁令显示在第一个图像上,但不会显示在第二个图像上。 (不要介意第二张图片的长度,我必须解决这个问题。)

<?php
$sql44 = "SELECT * FROM `sb_bans` ORDER BY `created` DESC LIMIT 6";
$res44 = mysqli_query($GLOBALS["___mysqli_ston"], $sql44) or trigger_error(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
$row44 = mysqli_fetch_assoc($res44);

while($row44 = mysqli_fetch_array($res44))
{
$sid1 = $row44['sid'];
$name1 = $row44['name'];
$steamid110 = $row44['authid'];
$reason1 = $row44['reason'];
$timesec = $row44['length'];
$unbanstatus = $row44['RemoveType'];

if($unbanstatus == "U")
{
$type1 = "(U)";
}
elseif($unbanstatus == "E")
{
$type1 = "(E)";
}
else
{
$type1 = "";
}
if($sid = 1)
{
$serv = "<img src='http://bans.versound.net/images/games/gmodttt.png' alt='TTT' />";
}
elseif($sid = 2)
{
$serv = "TF2 AU";
}
elseif($sid = 3)
{
$serv = "SB AU";
}
else
{
$serv = "wtf";
}
if($name1 == NULL)
{
$name1 = "no nickname present";
}
else
{
$name1 = $name1;
}
if($timesec == "0")
{
$length1 = "Permanent";
}
else
{
$length2 = gmdate("d", $timesec);
$length1 = "$length2 days";
}
echo "<tr style='" . $type2 . "'>\n<td style='text-align:center'>" . $serv . "</td>\n<td><a href='http://bans.versound.net/index.php?p=banlist&amp;advSearch=" . $steamid110 . "&amp;advType=steamid&amp;Submit' target='_blank'>" . $name1 . "</a></td>\n<td>" . $reason1 . "</td>\n<td>" . $length1 . " " . $type1 . "</td>\n</tr>\n";
}
?>

为什么会出现这种情况?你能帮助我吗?另外,我使用 DESC LIMIT 6,因为 DESC LIMIT 5 会错过第一个结果,并且只输出 4 个结果。

最佳答案

因为您不必要地调用了一个fetch,并且在调用您使用的真正的fetch之前浪费了它。

$row44 = mysqli_fetch_assoc($res44);  //This line is not needed and should go

while($row44 = mysqli_fetch_array($res44))

应该只是

while($row44 = mysqli_fetch_array($res44))

关于php - 为什么这段代码会错过第一个条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16644377/

相关文章:

php - MySql 查询 - 检查数据是否存在,如果存在则获取 id,如果不存在则添加数据并获取 id

php - 仅验证 Paypal 电子邮件

php - 如何将两张表的数据库数据内容复制到一张表中

mysql - 使用 R 操作向量值

php - Laravel 5.5 中的多重身份验证

php - 在准备好的语句中使用通配符

PHP:类内不允许使用备用关联数组表示法?

PHP 相当于第 n 个 child

php/mysql 事务在失败时不回滚(Codeigniter 框架)

php - 如何检查 UPDATE mysqli 查询是否正确执行?