【问题标题】:couldnt show data php in html无法在 html 中显示数据 php
【发布时间】:2015-01-20 11:43:46
【问题描述】:

我在代码中遇到提取问题。该语句无法返回 $row[] 中的值。我之前已经声明了变量,但结果中只能显示一个变量。这是我的代码:

<?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>

请帮我解决这个问题。谢谢

【问题讨论】:

  • 如果我从我的变量中删除 =null,未定义变量会显示错误

标签: php html postgresql pdo


【解决方案1】:

您在 while 子句的每次迭代中都覆盖了结果:

您希望在处理记录集中的每一行时输出 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>

【讨论】:

  • 我已经用你的代码试过了,结果除了 no_po 之外仍然是空的。
猜你喜欢
  • 1970-01-01
  • 2013-03-22
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-24
  • 1970-01-01
相关资源
最近更新 更多