如何使用PDO在html中回显数据php

时间:2014-11-22 15:04:02

标签: php html pdo

我的html中的echo php数据有问题。我想在html标签内回显数据,但它不起作用。

<?php
//require_once('function.php');
//session_start();

//if (!is_user()) {
//  redirect('signin.php');
//}
$no_po ;
$nama_barang=null; 
$nama_klien=null;
$harga_jual=null;
$qty=null;
$total_harga=null;
$status_po=null;
$tgl_po=null;
$tgl_kirim=null;
$nama_gudang=null;
$keterangan=null;
$page_title = "Purchase Order";
include_once 'header.php';

$no_po = $_GET['no_po'];

// include database and object files
include_once 'config/database.php';

//$total_harga = $harga_jual * $qty;
// instantiate database and product object
$database = new Database();
$db = $database->getConnection();

$query = "SELECT 
          po.no_po, 
          barang.nama_barang, 
          klien.nama_klien, 
          po.tgl_po, 
          po.qty, 
          barang.harga_jual, 
          po.status_po, 
          po.keterangan, 
          surat_pengantar.tgl_kirim, 
          gudang.nama_gudang,
           barang.harga_jual * po.qty AS total_harga
        FROM 
          public.po, 
          public.barang, 
          public.klien, 
          public.good_receipt, 
          public.gudang, 
          public.surat_pengantar
        WHERE 
         po.no_po = ?   
          po.id_barang = barang.id_barang AND
          po.id_klien = klien.id_klien AND
          po.no_po = surat_pengantar.no_po AND
          po.no_po = good_receipt.no_po AND
          gudang.id_gudang = good_receipt.id_gudang";

  $stmt = $db->prepare( $query );
  $stmt->bindParam(1,$no_po);
  $stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
   $tgl_po = $row['tgl_po'];}

?> 

   <body>



    <div class="container">
      <div class="row">
        <div class="col-xs-6">
          <h1>
            <a href="https://twitter.com/tahirtaous">
            <img src="YSU.png">
            Logo here
            </a>
          </h1>
        </div>
        <div class="col-xs-6 text-right">
          <h1>Purchase Order</h1>
          <h1><small><?php echo $no_po?></small></h1>
        </div>
      </div>
      <div class="row">

        <div class="col-xs-5">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h4>From: <a href="#">Your Name</a></h4>
            </div>
            <div class="panel-body">
              <p>
                Address <br>
                details <br>
                more <br>
              </p>
            </div>
          </div>
        </div>
        <div class="col-xs-5 col-xs-offset-2 text-right">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h4>Detail Invoice</h4>
            </div>
            <div class="panel-body">
              <table border="0">
              <tr>
              <td>Tanggal PO</td>
              <td>:</td>
              <?php echo "<td>{$tgl_po}</td>";?>
              </tr>

               <tr>
              <td>Gudang</td>
              <td>:</td>
              <td><?php echo $nama_gudang?></td>
              </tr>

              <tr>
              <td>Nama Pelanggan</td>
              <td>:</td>
              <td><?php echo $nama_klien?></td>
              </tr>

              <tr>
              <td>Status Purchase Order</td>
              <td>:</td>
              <td><?php echo $status_po?></td>
              </tr>

              <tr>
              <td>Tanggal Kirim</td>
              <td>:</td>
              <td><?php echo $tgl_kirim?></td>
              </tr>

              <tr>
              <td>Mata Uang</td>
              <td>:</td>
              <td>IDR(Rp)</td>
              </tr>

              <tr>
              <td>Term Pembayaran</td>
              <td>:</td>
              <td>30 hari</td>
              </tr>
              </table>
            </div>
          </div>
        </div>
      </div>
      <!-- / end client details section -->

      <table class="table table-bordered">
        <thead>
          <tr>
          <th>
              <h4>No.item</h4>
            </th>
            <th>
              <h4>Nama barang</h4>
            </th>
            <th>
              <h4>Quantity</h4>
            </th>
            <th>
              <h4>Price</h4>
            </th>
            <th>
              <h4>Keterangan</h4>
            </th>
            <th>
              <h4>Sub Total</h4>
            </th>
          </tr>
        </thead>
        <tbody>
        <?php   
            $no=1;
          echo "<tr>";
            echo "<td>{$no}</td>";
            echo"<td>{$nama_barang}</td>";
            echo"<td>{$qty}</td>";
            echo"<td class='text-right'>{$harga_jual}</td>";
            echo"<td class='text-right'>{$keterangan}</td>";
            echo"<td class='text-right'>{$total_harga}</td>";
          echo"</tr>";
          $no++;
        echo"</tbody>";

      echo"</table>";
      ?>
      <div class="row text-right">
        <div class="col-xs-2 col-xs-offset-8">
          <p>
            <strong>
            Total : <br>
            </strong>
          </p>
        </div>
        <div class="col-xs-2">
          <strong>
          Rp<?php echo $total_harga?> <br>
          </strong>
        </div>
      </div>
      </div>
    </div>


</body>
</html>

相反,我在html标签内调用了带有echo的数据,但结果是空的。请帮我解决这个问题。

0 个答案:

没有答案