如何阻止我的SQL查询显示两次结果?

时间:2014-03-03 07:56:19

标签: php html mysql sql

如何阻止结果在网页上显示两次?我做错了什么?是的,这是一个游戏,但它可以帮助我学习SQL和PHP。请生殖器这是我的第一次。 有一个数据库有两个表。数据库是game_tittle,两个表是player_data,第二个是character_data。

<?php  
include('db_conn.php');
#for connecting to SQL
$sqlget = "SELECT player_data.PlayerName, Character_data.Duration, character_data.KillsZ, character_data.KillsB, character_data.KillsH, character_data.HeadshotsZ, character_data.Humanity, character_data.Generation, character_data.InstanceID FROM player_data, character_data";
$sqldata = mysqli_query($dbcon, $sqlget) or die('error getting data');
echo "<center><table>";
echo "<tr> <th>Player Name</th><th>play time</th><th>Total Kills</th><th>Bandit kills</th><th>Hero Kills</th><th>Head shots</th><th>Humanity</th><th>Alive count</th><th>Instance ID</tr>";
  while ($row = mysqli_fetch_array($sqldata)) {

    echo "<tr><td>";
    echo $row['PlayerName'];
    echo "</td><td>";
    echo $row['Duration'];
    echo "</td><td>";
    echo $row['KillsZ'];
    echo "</td><td>";
    echo $row['KillsB'];
    echo "</td><td>";
    echo $row['KillsH'];
    echo "</td><td>";
    echo $row['HeadshotsZ'];
    echo "</td><td>";
    echo $row['Humanity'];
    echo "</td><td>";
    echo $row['Generation'];
    echo "</td><td>";
    echo $row['InstanceID'];
    echo "</td></tr>";
    echo "</center>";
    }

    echo "</table>";
    #end of table



?>

让它以这种方式工作。

<?php  
include('db_conn.php');
$sqlget = "SELECT player_data.PlayerUID, character_data.PlayerUID, player_data.PlayerName, character_data.HeadshotsZ, character_data.KillsZ, character_data.KillsH, character_data.KillsB, character_data.Alive, character_data.Generation, character_data.Humanity, character_data.InstanceID FROM player_data INNER JOIN character_data ON player_data.PlayerUID = character_data.PlayerUID";
$sqldata = mysqli_query($dbcon, $sqlget) or die('error getting data');
echo "<center><table>";
echo "<tr> <th>Player Name</th><th>Head shots</th><th>Total Kills</th><th>Hero kills</th><th>Bandit Kills</th><th>Live or dead</th><th>Lifes</th><th>Humanity</th><th>Instance ID</tr>";
  while ($row = mysqli_fetch_assoc($sqldata)) {

    echo "<tr><td>";
    echo $row['PlayerName'];
    echo "</td><td>";
    echo $row['HeadshotsZ'];
    echo "</td><td>";
    echo $row['KillsZ'];
    echo "</td><td>";
    echo $row['KillsH'];
    echo "</td><td>";
    echo $row['KillsB'];
    echo "</td><td>";
    echo $row['Alive'];
    echo "</td><td>";
    echo $row['Generation'];
    echo "</td><td>";
    echo $row['Humanity'];
    echo "</td><td>";
    echo $row['InstanceID'];
    echo "</td></tr>";
    echo "</center>";
    }

    echo "</table>";
    #end of table



?>

1 个答案:

答案 0 :(得分:1)

SQL查询中的错误:您忘记使用“where”-clause加入表。