looping saat upload data

Hallo selamat pagi teman2.. saya mau tnya ni, saat saya upload data, action download dan detail nya di inputan kedua jadi double..

daftar_buku

<thead>
                    <tr>
                      <th><center>JUDUL</center></th>
                      <th><center>KETERANGAN</center></th>
                      <th><center>FILE</center></th>
                      <th><center>ACTION</center></th>
                    </tr>
              </thead>
              <tbody>
              <?php
                $ambildata  = (mysqli_query($con,"SELECT * FROM tb_perpustakaan"));
                while($data=mysqli_fetch_array($ambildata)){
                ?>
            <tr>
                <td><center><?=$data['nama_buku']?></center></td>
                <td><center><?=$data['keterangan']?></center></td>
                <td><center><?=$data['file']?></center></td>
                <td>
                    <?php
                      $query  = "SELECT * FROM tb_perpustakaan";
                      $run    = mysqli_query($con,$query);

                      while($rows = mysqli_fetch_assoc($run)) {
                    ?>
                  <a href="download.php?file=<?php echo $rows['file'] ?>"><i class="fa fa-download" aria-hidden="true"></i></a>
                  <a href="detail.php?id_perpustakaan=<?php echo $rows['id_perpustakaan']?>"><i class="fa fa-eye"></i></a>
                  <?php
                      };
                    ?>
                </td>
            </tr>
            <?php
        };
          ?>
        </tbody>
                  </table>

download

<?php
    if(!empty($_GET['file'])) {
        $file_name = basename($_GET['file']);
        $filePath  = "berkas/".$file_name;

        if(!empty($file_name) && file_exists($filePath)) {
            //define header
            header("Cache-Control: public");
            header("Content-Description: File Transfer");
            header("Content-Disposition: attachment; filename=$file_name");
            header("Content-Type: application/pdf");
            header("Content-Transfer-Encoding: binary");

            //read file
            readfile($filePath);
            exit;
        }
            else {
                echo "file not exit";
            }
    }
?>

detail

//query
    $query  = "SELECT * FROM tb_perpustakaan WHERE id_perpustakaan='$id_perpustakaan'";
    //hasil
    $hasil  = $con->query($query);

    //uraikan tb_perpust
    $row = $hasil->fetch_assoc();
?>

                <!-- <div class="col-12"> -->
                  <div class="card-body" col="10">
                <table border = "1" id="daftarbuku" class="table table-bordered table-hover">
                  <thead>
                    <tr>
                      <th><center>JUDUL</center></th>
                      <th><center>KETERANGAN</center></th>
                      <th><center>FILE</center></th>
                    </tr>
              </thead>
              <tbody>
              <?php
                $ambildata  = (mysqli_query($con,"SELECT * FROM tb_perpustakaan"));
                while($data=mysqli_fetch_array($ambildata)){
                ?>
            <tr>
                <td><center><?=$data['nama_buku']?></center></td>
                <td><center><?=$data['keterangan']?></center></td>
                <td><center><?=$data['file']?></center></td>
            </tr>
            <?php
        };
          ?>

hasil

Screenshot 2022-09-20 102932.jpg

avatar novaje
@novaje

28 Kontribusi 3 Poin

Diperbarui 2 tahun yang lalu

1 Jawaban:

Jawaban Terpilih

<div>Itu di script data_buku, kamu running query dan loopingnya 2x&nbsp;</div><pre>&lt;thead&gt; &lt;tr&gt; &lt;th&gt;&lt;center&gt;JUDUL&lt;/center&gt;&lt;/th&gt; &lt;th&gt;&lt;center&gt;KETERANGAN&lt;/center&gt;&lt;/th&gt; &lt;th&gt;&lt;center&gt;FILE&lt;/center&gt;&lt;/th&gt; &lt;th&gt;&lt;center&gt;ACTION&lt;/center&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php $ambildata = (mysqli_query($con,"SELECT * FROM tb_perpustakaan")); &lt;-- RUNNING QUERY KE-1 while($data=mysqli_fetch_array($ambildata)){ &lt;-- LOOPING KE -1 ?&gt; &lt;tr&gt; &lt;td&gt;&lt;center&gt;&lt;?=$data['nama_buku']?&gt;&lt;/center&gt;&lt;/td&gt; &lt;td&gt;&lt;center&gt;&lt;?=$data['keterangan']?&gt;&lt;/center&gt;&lt;/td&gt; &lt;td&gt;&lt;center&gt;&lt;?=$data['file']?&gt;&lt;/center&gt;&lt;/td&gt; &lt;td&gt; &lt;?php $query = "SELECT * FROM tb_perpustakaan"; $run = mysqli_query($con,$query); &lt;-- RUNNING QUERY KE-2

          while($rows = mysqli_fetch_assoc($run)) { &amp;lt;-- LOOPING KE-2
        ?&amp;gt;
      &amp;lt;a href=&quot;download.php?file=&amp;lt;?php echo $rows[&#039;file&#039;] ?&amp;gt;&quot;&amp;gt;&amp;lt;i class=&quot;fa fa-download&quot; aria-hidden=&quot;true&quot;&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/a&amp;gt;
      &amp;lt;a href=&quot;detail.php?id_perpustakaan=&amp;lt;?php echo $rows[&#039;id_perpustakaan&#039;]?&amp;gt;&quot;&amp;gt;&amp;lt;i class=&quot;fa fa-eye&quot;&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/a&amp;gt;
      &amp;lt;?php
          };
        ?&amp;gt;
    &amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;
&amp;lt;?php

}; ?&gt; &lt;/tbody&gt; &lt;/table&gt;</pre><div><br>Coba scriptnya ubah jadi kaya gini :</div><pre>&lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;&lt;center&gt;JUDUL&lt;/center&gt;&lt;/th&gt; &lt;th&gt;&lt;center&gt;KETERANGAN&lt;/center&gt;&lt;/th&gt; &lt;th&gt;&lt;center&gt;FILE&lt;/center&gt;&lt;/th&gt; &lt;th&gt;&lt;center&gt;ACTION&lt;/center&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php $ambildata = (mysqli_query($con,"SELECT * FROM tb_perpustakaan")); while($data=mysqli_fetch_array($ambildata)){ ?&gt; &lt;tr&gt; &lt;td&gt;&lt;center&gt;&lt;?=$data['nama_buku']?&gt;&lt;/center&gt;&lt;/td&gt; &lt;td&gt;&lt;center&gt;&lt;?=$data['keterangan']?&gt;&lt;/center&gt;&lt;/td&gt; &lt;td&gt;&lt;center&gt;&lt;?=$data['file']?&gt;&lt;/center&gt;&lt;/td&gt; &lt;td&gt; &lt;a href="download.php?file=&lt;?php echo $data['file'] ?&gt;"&gt;&lt;i class="fa fa-download" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; &lt;a href="detail.php?id_perpustakaan=&lt;?php echo $data['id_perpustakaan']?&gt;"&gt;&lt;i class="fa fa-eye"&gt;&lt;/i&gt;&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php }; ?&gt; &lt;/tbody&gt; &lt;/table&gt;</pre><div><br><br>Semoga berhasil.</div><div><br></div>

avatar ahanafi
@ahanafi

815 Kontribusi 554 Poin

Dipost 2 tahun yang lalu

Tanggapan

baik bg sudah bisaaa. trimksi banyakk bg :)

Login untuk ikut Jawaban