我使用这些来显示带有行的表:
它只显示一行,但我在mysql中有大约300个。
我不知道有什么问题?有人可以帮帮我吗?
我尝试使用此代码:
while($dnn = mysql_fetch_array($query, MYSQL_ASSOC)) {
$hour = $dnn['BanH']; $day = $dnn['BanD']; $month = $dnn['BanM']; $year = $dnn['BanY'];
$uhour = $dnn['UnbanH']; $uday = $dnn['UnbanD']; $umonth = $dnn['UnbanM']; $uyear = $dnn['UnbanY'];
$yaro = $dnn['Name']; $dalil = $dnn['Reason']; $bokon = $dnn['Admin'];
if($dnn['Days'] == 0) {
$bantime = "Never <font color=red>(Banned Permanently)</font>";
}
else {
$bantime = "$uday/$umonth/$uyear, $uhour:00";
}
$banlist = "<tr><td class=\"trow1\" align=\"center\"><a href=User-{$yaro}><font color=white>{$yaro}</a></font></td>
<td class=\"trow1\" align=\"center\">{$day}/{$month}/{$year}, {$hour}:00</td>
<td class=\"trow1\" align=\"center\">{$bantime}</td>
<td class=\"trow1\" align=\"center\">{$dalil}</td>
<td class=\"trow1\" align=\"center\">{$bokon}</td>
</tr>";
}
if($banlist == '')
{
$banlist = '<tr><td colspan="5">'.$lang->no_banned.'</td></tr>';
}
$bans .= $banlist;
$page = "
<html>
<head>
<title>Banned Users List</title>
{$headerinclude}
</head>
<body>
{$header}
<br />
<table border=0 cellspacing={$theme['borderwidth']} cellpadding={$theme['tablespace']} class=tborder>
<tr>
<td class=thead colspan=5><span class=smalltext><strong>Banned Users List</strong></span></td>
</tr>
<tr>
<td class=tcat align=center>Player</td>
<td class=tcat align=center>Ban Date</td>
<td class=tcat align=center>Unban Date</td>
<td class=tcat align=center>Ban Reason</td>
<td class=tcat align=center>Banned By</td>
</tr>
{$bans}
</tbody></table>
{$footer}
</body>
</html>";
output_page($page);
我尝试使用http://php.net/manual/en/function.mysql-fetch-array.php示例。 **抱歉我的英语不好。
答案 0 :(得分:0)
你做错了。在每次循环中,banlist
的值被覆盖 - 因此,您只获得最后一行的值。
你需要这样做:
$banlist = '';
while($dnn = mysql_fetch_array($query, MYSQL_ASSOC)) {
$hour = $dnn['BanH']; $day = $dnn['BanD']; $month = $dnn['BanM']; $year = $dnn['BanY'];
$uhour = $dnn['UnbanH']; $uday = $dnn['UnbanD']; $umonth = $dnn['UnbanM']; $uyear = $dnn['UnbanY'];
$yaro = $dnn['Name']; $dalil = $dnn['Reason']; $bokon = $dnn['Admin'];
if($dnn['Days'] == 0) {
$bantime = "Never <font color=red>(Banned Permanently)</font>";
}
else {
$bantime = "$uday/$umonth/$uyear, $uhour:00";
}
$banlist .= "<tr><td class=\"trow1\" align=\"center\"><a href=User-{$yaro}><font color=white>{$yaro}</a></font></td>
<td class=\"trow1\" align=\"center\">{$day}/{$month}/{$year}, {$hour}:00</td>
<td class=\"trow1\" align=\"center\">{$bantime}</td>
<td class=\"trow1\" align=\"center\">{$dalil}</td>
<td class=\"trow1\" align=\"center\">{$bokon}</td>
</tr>";
}