简体   繁体   English

用php mysqli从2个表显示数据; 什么也没显示

[英]Showing data from 2 tables with php mysqli; doesn't show anything

I have a problem when showing data from 2 tables; 显示2个表中的数据时出现问题; pegawai and pilihan. pegawai和pilihan。 PK pegawai = nokom, pilihan = kdpilih. PK pegawai = nokom,pilihan = kdpilih。 For now, the data on pegawai table contain 3 data/rows, but why doesn't show anything? 目前,pegawai表上的数据包含3个数据/行,但是为什么不显示任何内容? If the data show correctly, will it show only the name and not numbers? 如果数据正确显示,是否仅显示名称而不显示数字?

Tables: 表格:

pegawai: nokom, nip, nama, jk, agama pegawai:nokom,nip,nama,jk,agama

pilihan: kdpilih, nmpilih pilihan:kdpilih,nmpilih

jk and agama contain numbers from kdpilih on pilihan table, here is my code: jk和agama包含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>

any help will be so thankful. 任何帮助都会非常感激。 Thanks 谢谢

finally works, i did: 终于可以了,我做到了:

$sql = "SELECT a.nokom, a.nip, a.nama, a.agama, b.nmpilih AS jk, c.nmpilih as agama FROM pegawai a JOIN pilihan b ON b.kdpilih = a.jk JOIN pilihan c ON c.kdpilih = a.agama ORDER BY a.nip ASC"; $ sql =“ SELECT a.nokom,a.nip,a.nama,a.agama,b.nmpilih AS jk,c.nmpilih as agama来自pegawai a JOIN pilihan b ON b.kdpilih = a.jk JOIN pilihan c ON c.kdpilih = a.agama ORDER BY a.nip ASC”;

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

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