Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php mysqli显示来自2个表的数据;什么也看不出来_Php_Mysqli - Fatal编程技术网

使用php mysqli显示来自2个表的数据;什么也看不出来

使用php mysqli显示来自2个表的数据;什么也看不出来,php,mysqli,Php,Mysqli,显示两个表中的数据时出现问题;pegawai和pilihan。PK pegawai=nokom,pilihan=kdpilih。目前,pegawai表上的数据包含3个数据/行,但为什么不显示任何内容?如果数据显示正确,是否只显示名称而不显示数字 表: pegawai:nokom,nip,nama,jk,agama 皮里汉:克德皮里,恩皮里 jk和agama包含pilihan表中kdpilih的数字,以下是我的代码: <div class="table-responsive table-bo

显示两个表中的数据时出现问题;pegawai和pilihan。PK pegawai=nokom,pilihan=kdpilih。目前,pegawai表上的数据包含3个数据/行,但为什么不显示任何内容?如果数据显示正确,是否只显示名称而不显示数字

表:

pegawai:nokom,nip,nama,jk,agama

皮里汉:克德皮里,恩皮里

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>
任何帮助都会非常感激。谢谢

终于成功了,我做到了:

$sql=选择a.nokom、a.nip、a.nama、a.agama、b.nmpilih作为jk、c.nmpilih作为agama从pegawai a上加入pilihan b
b、 kdpilih=a.jk通过a.nip ASC在c.kdpilih=a.agama订单上加入pilihan c

nip来自哪个表?@Faradox pegawai表尝试以下操作:选择*来自pegawai p LEFT JOIN pilihan ph ON ph.kdpilih=p.nokom按p.nip ASC排序。并确保ph.kdpilih=p.nokom相同的数据$result=mysqli_query$conn、$sql或diemysqli_error$conn;放在这里,检查准确的错误发生了什么这是你的连接mysqli\u connect