自从我做了一个排行榜,我发现我需要使用多个表来获取我所有的数据。由于我使用了 MySQLi Join,它给了我这个错误:
注意:尝试在第 92 行的 /Applications/XAMPP/xamppfiles/htdocs/Minecraft-User-Info/leaderboard/index.php 中获取非对象的属性
这是第 92 行:
if ($result->num_rows > 0) {
但在我使用 SQL Join 之前,它工作得很好。这是我的完整 PHP 代码:
<?php
$result = mysqli_query($con, "SELECT
User_Management.Leaderboard_Tag.Username, User_Management.Leaderboard_Tag.Wins, User_Management.Leaderboard_Tag.Got_Tagged ,User_Management.Player_Data.Tokens @rn := @rn + 1 as Rank
FROM Leaderboard_Tag, Player_Data WHERE Player_Data.UUID=Leaderboard_Tag.UUID AND @rn > 0 )
ORDER BY Wins,Got_Tagged");
$rank = 1;
if ($result->num_rows > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$Username=$row['User_Management.Leaderboard_Tag.Username'];
$Tokens = $row['User_Management.Player_Data.Tokens'];
$Wins=$row['User_Management.Leaderboard_Tag.Wins,'];
$Got_Tagged = $row['User_Management.Leaderboard_Tag.Got_Tagged'];
echo "<tr>
<td class=\"rank\">$rank</td>
<td><div class=\"row\">
<div class=\"td-avatar\">
<img class=\"avatar-small\" src=\"http://website.craftshark.net/avatar/avatar/$Username/40\">
</div>
<div class=\"td-user\">
<a class=\"lb-username\" href=\"../player/$Username\">$Username</a>
<br>
<small class=\"lb-desc\"><i class=\"fa fa-star tokens-small\"></i> $Tokens</small>
</div>
</div></td>
<td class=\"got_tagged\">$Got_Tagged</td>
<td class=\"wins\">$Wins</td>
</tr>";
$rank++;
}
}
/* close connection */
mysqli_close($con);
?>
表方案:
Leaderboard_Tag:
- Username (Same values as *)
- UUID (Same values as *)
- Wins
- Got_Tagged
Player_Data:
-* Username
-* UUID
- IP
- Rank
- Tokens
我看不出有什么不对。我以前从未使用过 MySQLi Join,但我搜索并遵循了有关如何执行此操作的教程。有人看错了吗?