我正在尝试从游戏服务器数据库中提取一些统计数据,并将它们返回到一个表中。
我已经设法做到了第一点 - 拉出 10 个结果,显示在 html 的表格中,但是……下一点让我很难过……对于每个玩家,我想从另一个表格中获取一些信息……
这是我到目前为止所拥有的......请原谅凌乱的代码,我只是在学习!
// adding ALL info from the first 10 tables 'profile' based on humanity, ascending, to the variable 'profile_info'
$profile_info = mysql_query("SELECT * FROM profile ORDER BY humanity desc LIMIT 10");
while($row = mysql_fetch_array($profile_info))
{
// Below I add the players unique ID into the variable $unique, to be used later for pulling their survival time from the 2nd table, which is called 'survivor'
$unique = $row['unique_id'];
echo "<tr>";
echo "<td class=\"c1\">" . $row['name'] . "</td>";
echo "<td class=\"c2\">" . $row['humanity'] . "</td>";
echo "<td class=\"c3\">" . $row['total_survivor_kills'] . "</td>";
echo "<td class=\"c4\">" . $row['total_bandit_kills'] . "</td>";
echo "<td class=\"c5\">" . $row['total_zombie_kills'] . "</td>";
echo "<td class=\"c6\">" . $unique . "</td>";
//In the line below, I try to get data from the 2nd table (called survivor), checking for the unique_id for the player (extracted from the first table, called 'profile') which is common across both tables and which have a 0 in the field 'is_dead'
$result = mysql_query("SELECT * FROM `survivor` WHERE `unique_id` ='.$unique' AND `is_dead` = 0") or die(mysql_error());
echo $unique;
if (mysql_num_rows($result)) {
$survivors_survival_time = mysql_fetch_assoc($result);
echo "<td class=\"c7\">" . $survivors_survival_time['survival_time'] . "</td>";
}
我希望,即使上面的代码可能是垃圾,你也能看到我在做什么?
大部分工作正常,只是我尝试从第二个表中获取玩家信息的部分,基于他们在第一个表中的行中的 unique_id,它不起作用:(
有什么想法,或者上面的内容太糟糕了,我应该放弃吗?