这是我的sql查询的php代码,多次给我相同的值


if (isset($_GET["q"]))
 {

   $q= $_GET["q"];

$link=mysqli_connect("localhost","root","");
  mysqli_select_db($link,"onesports");
$result=mysqli_query($link,"select  players.full_name, team.* from players,team where team.team_name='" .$q. " ' and players.team_name=team.team_name ");



echo "<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";

    echo "<td>" . $row['id'] . "</td>";
    echo "<a href=>" . $row['full_name'] . "</a>";
    echo "<td>" . $row['image'] . "</td>";
    echo "<td>" . $row['team_name'] . "</td>";
    echo "<td>" . $row['prov'] . "</td>";
    echo "<td>" . $row['city'] . "</td>";
    echo "<td>" . $row['captain'] . "</td>";
    echo "<td>" . $row['coach'] . "</td>";
    echo "</tr>";
}
echo "</table>";


}
else {
   echo "no result found.";

}


它给了我这个输出
enter image description here

我只想要玩家姓名和剩余价值一次

最佳答案

在这种情况下,您应该使用INNER JOIN

只需使用以下代码更新您的代码。

$result = mysqli_query($link, "SELECT `players`.full_name,`team`.* FROM `players` INNER JOIN `team` ON  `players`.team_name= `team`.team_name AND `team`.team_name='".$q."'");

08-07 12:09