2014-11-22 87 views
0

我在我的代碼中面臨提取問題。該語句無法返回$ row []中的值。我之前已經聲明瞭變量,但只有一個變量可以顯示在結果中。這裏是我的代碼:無法在html中顯示數據php

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

//if (!is_user()) { 
// redirect('signin.php'); 
//} 

$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 
      no_po = :no_po AND  
      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(':no_po',$no_po); 
    $result = $stmt->execute(); 

$no_po ; 
$nama_barang=null; 
$harga_jual=null; 
$qty=null; 
$nama_klien=null; 
$total_harga=null; 
$status_po=null; 
$tgl_po=null; 
$tgl_kirim=null; 
$nama_gudang=null; 
$keterangan=null; 

    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ 
    $no_po = $row['no_po']; 
    $nama_barang = $row['nama_barang']; 
    $nama_klien = $row['nama_klien']; 
    $tgl_po = $row['tgl_po']; 
    $qty = $row['qty']; 
    $harga_jual = number_format($row['harga_jual'],0,",","."); 
    $status_po = $row['status_po']; 
    $keterangan = $row['keterangan']; 
    $tgl_kirim = $row['tgl_kirim']; 
    $nama_gudang = $row['nama_gudang']; 
    $total_harga = number_format($row['total_harga'],0,",","."); 


} 


?> 

    <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> 
       <td><?php echo $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> 

請幫我解決這個問題。感謝

+0

如果我抹去= null,以從我的變量,與undifined可變 – 2014-11-22 10:39:56

回答

0

您是在書寫你而條款的每一次迭代的結果:

你要輸出的HTML,你處理從記錄每一行。

我認爲你正在尋找做這樣的事情雖然已經有相當一段時間,因爲我寫的程序PHP:

<body> 

<?php 

    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ 
    $no_po = $row['no_po']; 
    $nama_barang = $row['nama_barang']; 
    $nama_klien = $row['nama_klien']; 
    $tgl_po = $row['tgl_po']; 
    $qty = $row['qty']; 
    $harga_jual = number_format($row['harga_jual'],0,",","."); 
    $status_po = $row['status_po']; 
    $keterangan = $row['keterangan']; 
    $tgl_kirim = $row['tgl_kirim']; 
    $nama_gudang = $row['nama_gudang']; 
    $total_harga = number_format($row['total_harga'],0,",","."); 
?> 
    <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> 
       <td><?php echo $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> 
+0

我有顯示錯誤試着用你的代碼,但仍然得到的結果是空的,除了no_po。 – 2014-11-22 10:57:32