Taking data from multiple tables

How would i join information from tables if they have the same name but different values? i am trying to join the name column from the Players table but i am already using name from the Minigames table to join the names?

database tables and output is here: http://imgur.com/a/38VpP

[php]

<?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "9606"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT PlayerStats.player_id, Minigames.minigame_id, PlayerStats.stat, Minigames.name, PlayerStats.value FROM PlayerStats INNER JOIN Minigames ON PlayerStats.minigame_id = Minigames.minigame_id"; $result = $conn->query($sql); if ($result->num_rows > 0) { echo ""; // output data of each row while($row = $result->fetch_assoc()) { echo ""; } }else { echo "0 results"; } $conn->close(); ?>[/php]
Game Player Stat Value
".$row["name"]." ".$row["player_id"]." ".$row["stat"]." ".$row["value"]."

You just need to add playerstats.nameto the query string. I wasn’t able to view your image, it’s blocked at my workplace, but I don’t think I need to, based on your explanation.

See below.

[php]$sql = “SELECT PlayerStats.player_id, Minigames.minigame_id, PlayerStats.stat, Minigames.name,PlayerStats.name, PlayerStats.value
FROM PlayerStats
INNER JOIN Minigames
ON PlayerStats.minigame_id = Minigames.minigame_id”;[/php]

If you are storing names in more than one place your database design is wrong. Look up and learn about Database Normalization. Its an easy subject to master and is very important to know.

Sponsor our Newsletter | Privacy Policy | Terms of Service