php | mysqli选择多表mysqli [保留]

问题描述 投票:-3回答:1

我试图从多表中选择多个信息,但很麻烦,如果有人可以帮助我,请问我如何查询此信息<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();
php mysqli
1个回答
0
投票

如果我理解您的问题,请尝试使用此方法:

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.”
© www.soinside.com 2019 - 2024. All rights reserved.