嗯,我不能真正具體說明我在標題中的問題,所以請原諒我。從mySQL數據庫中讀取多個表?
我製作了一個.php腳本,用於從我的數據庫中讀取數據並將其打印到頁面上的表格中。基本上它應該作爲禁止表。但我陷入了一個問題。由於該禁令在數據庫中的幾個不同的表中排序,我需要閱讀所有這些信息以獲取禁止列表中需要的特定詳細信息。我完成了大部分工作,但我無法獲得禁止「騙子」的管理員的姓名。以下是「admin_id」位於「處罰」表中的事情,admin的名稱位於「clients」表中。現在我無法弄清楚如何通過「處罰」表中的「admin_id」從「客戶」表中獲取管理員的姓名,並將其打印在同一頁面上。
所以this是我所做的,我只是缺少「管理員」的名稱。
以下是從數據庫中讀取當前信息的代碼。
mysql_query("SELECT penalties.id, penalties.type, penalties.time_add, penalties.time_expire,
penalties.reason, penalties.inactive, penalties.duration, penalties.admin_id,
target.id as target_id, target.name as target_name, target.ip as target_ip
FROM penalties, clients as target
WHERE (penalties.type = 'TempBan' OR penalties.type = 'Ban')
AND inactive = 0
AND penalties.client_id = target.id
ORDER BY penalties.id DESC")
or die(mysql_error());
您需要使用連接。 – Pitchinnate
你想聽聽[mysql JOIN](http://stackoverflow.com/questions/7877720/the-best-tutorial-on-joins-in-mysql)。 – moonwave99
建議使用mysqli或PDO_MySQL擴展。不建議在新的開發中使用舊的mysql擴展。 http://php.net/manual/en/book.mysqli.php http://php.net/manual/en/book.pdo.php –