簡體   English   中英

php | mysqli選擇多表mysqli [保留]

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

即時通訊試圖從多表中選擇多個信息,但很麻煩,如果有人可以幫助我進行一些指導,如何查詢此信息,我表示<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();

如果我了解您的問題,請嘗試使用此方法:

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.”

你需要加入三個表來從數據庫中獲得的數據(見https://www.w3schools.com/sql/sql_join_inner.asphttps://www.w3schools.com/sql/sql_join_left.asp )。

要加入三個表,您需要通過一些ID或名稱將它們連接起來。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM