[英]multiple arrays display in one table
我有一个表,用于显示用户当前的攻击等级和用户名。在该表中,我还有两列,我想显示玩家的经验值和玩家的排名。
我遇到的问题是玩家体验位于另一个表中,我不知道如何基于从第一个数组中提取的用户名来制作另一个数组来获取玩家体验。 而且排名也可以通过第一个数组来实现,但是我不知道如何使它在每个循环中显示一个递增的数字。
<table align="center">
<tr>
<th colspan="4"><font color="#d3d3d3">Attack Leaders</th>
</tr>
<tr>
<th width="100"><font color="#d3d3d3">Rank</th>
<th width="100"><font color="#d3d3d3">Username</th>
<th width="100"><font color="#d3d3d3">Experience</th>
<th width="100"><font color="#d3d3d3">Level </th>
</tr>
<?php
$sql = "SELECT user, cur_attack FROM curstats order by cur_attack desc LIMIT 25";
$result = mysql_query($sql) or die(mysql_error());
$user = $cut_attack = array();
while($row = mysql_fetch_assoc($result)) {
$user[] = $row['user'];
$cur_attack[] = $row['cur_attack'];
?>
<tr>
<td align="center"><font color="#d3d3d3"></font></td>
<td align="center"><font color="#d3d3d3"><?php echo $row['user'];?></font></td>
<td align="center"><font color="#d3d3d3"></font></td>
<td align="center"><font color="#d3d3d3"><?php echo $row['cur_attack'];?></font> </td></tr>
<?php
}
?>
</table
这是到现在页面的链接:
好的,我以您显示的方式写了查询,现在我得到字段列表中的“用户”列不明确
$sql = "SELECT user, cur_attack , experience.*
FROM curstats
LEFT JOIN experience
ON curstats.user = experience
order by cur_attack desc LIMIT 25";
$result = mysql_query($sql) or die(mysql_error());
$user = $cur_attack = $exp_attack = array();
while($row = mysql_fetch_assoc($result)) {
$user[] = $row['user'];
$cur_attack[] = $row['cur_attack'];
$exp_attack[] = $ROW['exp_attack'];
?>
<tr>
<td align="center"><font color="#d3d3d3"></font></td>
<td align="center"><font color="#d3d3d3"><?php echo $row['user'];?></font></td>
<td align="center"><font color="#d3d3d3"></font><?php echo $row['exp_attack']; ?></td>
<td align="center"><font color="#d3d3d3"><?php echo $row['cur_attack'];?></font> </td></tr>
只需在查询中使用联接
SELECT
c.user,
c.cur_attack,
e.exp_attack
FROM curstats c
LEFT JOIN experience e
ON c.user = e.user
ORDER BY c.cur_attack desc LIMIT 25
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.