0
從2個表格顯示數據時出現問題; pegawai和pilihan。 PK pegawai = nokom,pilihan = kdpilih。目前,pegawai表中的數據包含3個數據/行,但爲什麼不顯示任何內容?如果數據正確顯示,它只會顯示名稱而不顯示數字?使用php mysqli顯示2個表中的數據;不顯示任何東西
表:
pegawai:nokom,夾,非農產品市場準入,JK,阿含
pilihan:kdpilih,nmpilih
JK和阿含包含從pilihan表kdpilih號,這裏是我的代碼:
<div class="table-responsive table-bordered">
<table class="table table-striped">
<tr>
<th align="center" scope="col">NOKOM</th>
<th align="center" scope="col">NIP</th>
<th align="center" scope="col">NAMA</th>
<th align="center" scope="col">JK</th>
<th align="center" scope="col">AGAMA</th>
<th align="center" scope="col">Aksi</th>
</tr>
<?php
require "config.php";
$sql = "SELECT * FROM pegawai INNER JOIN pilihan ON pilihan.kdpilih = pegawai.nokom ORDER BY nip ASC";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
while ($data = mysqli_fetch_array($result))
{
echo "<tr class=\"table table-striped\">
<td valign=\"top\" align=\"left\">".$data['nokom']."</td>
<td valign=\"top\" align=\"left\">".$data['nip']."</td>
<td valign=\"top\" align=\"left\">".$data['nama']."</td>
<td valign=\"top\" align=\"left\">".$data['jk']."</td>
<td valign=\"top\" align=\"left\">".$data['agama']."</td>
<td valign=\"top\" align=\"left\">
<a href=\"pegawai_ubah.php?id=$data[id]\">Ubah</a>
<a href=\"pegawai_hapus.php?id=$data[id]\" onClick=\"return confirm('Apakah Anda yakin?');\">Hapus</a>
</td>
</tr>";
}
}
else
{
echo "Belum ada data.";
}
?>
</table>
</div>
任何幫助將如此感激。由於
'nip'從哪個表? – Faradox
@Faradox pegawai表 –
試試這個:'「SELECT * FROM pegawai p LEFT JOIN pilihan ph on ph.kdpilih = p.nokom ORDER BY p.nip ASC」'。並確保ph.kdpilih = p.nokom相同的數據 – Faradox