简体   繁体   English

尝试显示前10个得分-仅获得一个结果

[英]Trying to display top 10 scores - Only getting one result

I'm trying to create a leaderboards page which shows the top 10 users depending on how much money they have. 我正在尝试创建一个排行榜页面,该页面根据所拥有的资金显示前10名用户。 The code that I have created works, but only shows one result -- the user with the most money. 我创建的代码可以工作,但只能显示一个结果-资金最多的用户。 The problem is probably something simple, but I can't find anything to help. 问题可能很简单,但我找不到任何帮助。

Here is my code: 这是我的代码:

<?php

include "globals.php";

print "
<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'> Leaderboards </h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'><br> <br><br>";

$q=$db->query("SELECT * FROM users ORDER BY money DESC LIMIT 10;");
print "<table width=75% cellspacing=1 class='table'> <tr style='background:gray;'> <th>Username</th> <th>User Level</th><th>Amount</th> </tr>";
while($r=$db->fetch_row($q))
{
$money=money_formatter($r['money']);
print "<tr><td>{$r['username']}";
print "</td><td>{$r['level']}</td><td>{$money}</td></tr>";
print "</table></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";
}
$h->endpage();
?>

I can see a flaw in the code here. 我可以在这里看到代码中的缺陷。 Your line: 您的电话:

print "</table></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";

should be after the while loop, not inside it. 应该在while循环之后, while不是在其中。 As it is, you get broken HTML and you finish the table after the first result is printed. 照原样,您将破坏HTML并在打印第一个结果后完成表格。

您正在使用仅提取一条记录的fetch_row,是否意味着要使用fetch_array提取所有10条记录?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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