這裏是一個數據庫的例子。我們把這個數據庫表Player
:在不同的表中將PHP mysql ID改爲用戶名
+---------+----------+-------------+------------+------------+--+
| Name | pid | cash | bankacc | Random | |
+---------+----------+-------------+------------+------------+--+
| carl | 123 | non | 3434343434 | 34343433 | |
| petter | 456 | non | 3434343434 | 3434343434 | |
| sam | 1337 | non | 3434343434 | 3434343434 | |
| | | non | 3434343434 | 3434343434 | |
+---------+----------+-------------+------------+------------+--+
這裏是叫House
另一個表;在房子只顯示PID
:
+---------+----------+-------------+------------+------------+--+
| pid | owned | pos | random | Random | |
+---------+----------+-------------+------------+------------+--+
| 123 | categ | non | 3434343434 | 34343433 | |
| 456 | categ | non | 3434343434 | 3434343434 | |
| 1337 | tag | non | 3434343434 | 3434343434 | |
| 4 | tag | non | 3434343434 | 3434343434 | |
+---------+----------+-------------+------------+------------+--+
我試圖顯示此表在我的PHP的網站稱爲「家」,但我不希望顯示的「PID」,而不是「PID」我想房主的名字。
$sql = "SELECT pid, pos, owned FROM houses";
$ru = $conn->query($sql);
while ($row = $ru->fetch_assoc()) {
echo '<tr>';
echo '<td>'.$row['pid'].'</td>'; <--instead of pid I want the name in here
echo '<td>'.$row['pos'].'</td>';
echo '<td>'.$row['owned'].'</td>';
echo '<td class="text-right">';
echo '<button class="button tiny">View User</button>';
echo '<button class="button alert tiny">Delete</button>';
echo '</td>';
echo '</tr>';
}
?>
但這裏是一個查詢的例子,我想如何。真的很糟糕的例子。
$sql = "SELECT pid = name, pos, owned FROM houses, player";
解釋一下你的問題。什麼是你傳遞的想要的。 –
在你的sql語句中使用'INNER JOIN'。 –
您需要閱讀SQL教程,而不是隨意編寫代碼。 – Barmar