im trying to select multiple information from multi-tables but its a mess, please if someone can help me with some orientation how to query this i appreaciate <3
//Create the query and send it to the database.
$sql = "SELECT items.item_name, inventory.item_id, inventory.amount , player.id FROM items, inventory, player WHERE player.ID = '".$ID."'";
if ($result = $mysqli->query($sql))
{
/* fetch associative array */
$row = $result->fetch_assoc()
echo $row["item_name"];
echo $row["amount"];
/* free result set */
//$result->free();
}
$mysqli->close();
If I understand your question, try to use this:
SELECT items.item_name, inventory.item_id, inventory.ammount, player.id FROM items LEFT JOIN inventory ON items.id = inventory.items_id LEFT JOIN player ON “connect tables (player and items) with some id” WHERE player.ID = “.$ID.”
You need to JOIN three tables to get data FROM database ( see https://www.w3schools.com/sql/sql_join_inner.asp , https://www.w3schools.com/sql/sql_join_left.asp ).
To JOIN three tables you need to connect them by some ids or names.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.