为什么我无法在MySQL数据库中显示视图中的数据?

时间:2017-07-24 10:21:42

标签: php mysql

我想从数据库向我的php程序显示一些数据,但运行时数据无法显示?

这是我从phpmyadmin看来的视图

(select `m`.`id_mutasi` AS `id_mutasi`,`m`.`tgl_mutasi` AS `tgl_mutasi`,`m`.`kode_barang` AS `kode_barang`,`a`.`nm_barang` AS `nm_barang`,`m`.`ruang_lama` AS `ruang_lama`,`m`.`ruang_baru` AS `ruang_baru`,`u`.`nm_unit` AS `unit_lama`,`m`.`unit_baru` AS `unit_baru`,`i`.`user` AS `user_lama`,`m`.`userbaru` AS `user_baru`,`m`.`jumlah` AS `jumlah`,`m`.`user_posting` AS `user_posting` from ((((((`simaset`.`mutasi` `m` join `simaset`.`inventarisasi` `i` on((`m`.`kode_inventarisasi_baru` = `i`.`kode_inventarisasi`))) join `simaset`.`aset` `a` on((`a`.`kode_barang` = `m`.`kode_barang`))) join `simaset`.`ruangan` `r` on((`r`.`kode_ruangan` = `m`.`ruang_lama`))) join `simaset`.`ruangan` `rb` on((`rb`.`kode_ruangan` = `i`.`kode_ruangan`))) join `simaset`.`unit_kerja` `u` on((`u`.`kode_unit` = `m`.`unit_lama`))) join `simaset`.`unit_kerja` `ub` on((`ub`.`kode_unit` = `i`.`kode_unit`))))

这是我的PHP代码

<table id="table-example" class="table" cellpadding="0" cellspacing="0" border="0">
    <thead>
      <tr> 
        <!-- <th>NO</th> -->
        <th>ID Mutasi</th>
        <th>Tgl Mutasi</th>
        <th>Kode Barang</th>
        <th>Barang</th>
        <th>Dept Lama</th>
        <th>Jabatan Lama</th>
        <th>Dept Baru</th>            
        <th>Jabatan Baru</th>
        <!-- <th>User Baru</th> -->
        <th>Jumlah</th>
        <th>User Posting</th>
        <!-- <th>User Posting</th> -->
        <th>Aksi</th>
      </tr>
    </thead>
    <tbody>
     <!-- <?php $no = 1;?> -->
      <?php do { ?>
        <tr class=gradeX>
            <!-- <td><center><?php echo $no++ ?></center></td> -->
            <td><center>
              <?php echo $row_rs_data['id_mutasi']; ?>
            </center></td>
            <td><?php echo $row_rs_data['tgl_mutasi']; ?></td>
            <td ><?php echo $row_rs_data['kode_barang']; ?></td>
            <td ><?php echo $row_rs_data['nm_barang']; ?></td>
            <td ><?php echo $row_rs_data['ruanglama']; ?></td>
            <td ><?php echo $row_rs_data['unitlama']; ?></td>
            <td ><?php echo $row_rs_data['ruangbaru']; ?></td>
            <td ><?php echo $row_rs_data['unitbaru']; ?></td>
            <!-- <td ><?php echo $row_rs_data['userbaru']; ?></td> -->
            <td ><center><?php echo $row_rs_data['jumlah']; ?></center></td>
            <td ><?php echo $row_rs_data['user_posting']; ?></td>
            <td ><a href="?mod=pindah_inventaris&amp;act=delete&amp;id_mutasi=<?php echo $row_rs_data['id_mutasi']; ?>" onclick="return confirm('Hapus Data <?php echo $row_rs_data['nm_barang']; ?> ?')"><img src="img/icons/packs/silk/16x16/cross.png" width="16" height="16" alt="Hapus" title="Hapus" /></a></td>
        </tr>
        <?php
        echo "test";
         } while ($row_rs_data = mysql_fetch_assoc($rs_data)); ?>
    </tbody>
  </table>

1 个答案:

答案 0 :(得分:0)

替换<tbody>块。使用while代替do..whilemysqli代替mysql mysql已被弃用。

<tbody>
  <?php while ($row_rs_data = mysql_fetch_assoc($rs_data)){ ?>
    <tr class=gradeX>
        <!-- <td><center><?php echo $no++ ?></center></td> -->
        <td><center>
          <?php echo $row_rs_data['id_mutasi']; ?>
        </center></td>
        <td><?php echo $row_rs_data['tgl_mutasi']; ?></td>
        <td ><?php echo $row_rs_data['kode_barang']; ?></td>
        <td ><?php echo $row_rs_data['nm_barang']; ?></td>
        <td ><?php echo $row_rs_data['ruanglama']; ?></td>
        <td ><?php echo $row_rs_data['unitlama']; ?></td>
        <td ><?php echo $row_rs_data['ruangbaru']; ?></td>
        <td ><?php echo $row_rs_data['unitbaru']; ?></td>
        <!-- <td ><?php echo $row_rs_data['userbaru']; ?></td> -->
        <td ><center><?php echo $row_rs_data['jumlah']; ?></center></td>
        <td ><?php echo $row_rs_data['user_posting']; ?></td>
        <td ><a href="?mod=pindah_inventaris&amp;act=delete&amp;id_mutasi=<?php echo $row_rs_data['id_mutasi']; ?>" onclick="return confirm('Hapus Data <?php echo $row_rs_data['nm_barang']; ?> ?')"><img src="img/icons/packs/silk/16x16/cross.png" width="16" height="16" alt="Hapus" title="Hapus" /></a></td>
    </tr>
    <?php
    echo "test";
     } ?>
</tbody>