简体   繁体   English

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

[英]php | mysqli Select Multi tables mysqli [on hold]

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 即时通讯试图从多表中选择多个信息,但很麻烦,如果有人可以帮助我进行一些指导,如何查询此信息,我表示<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 ). 你需要加入三个表来从数据库中获得的数据(见https://www.w3schools.com/sql/sql_join_inner.asphttps://www.w3schools.com/sql/sql_join_left.asp )。

To JOIN three tables you need to connect them by some ids or names. 要加入三个表,您需要通过一些ID或名称将它们连接起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM