title: How to make order history to online shop in php?
body: <p><strong>Problems</strong>:</p>
  
  <p>1) Just 3 <code>id_penjualan</code> rows were displayed in order history, it should be 4 <code>id_penjualan</code> rows.</p>
  
  <p>2) <code>jumlah</code> and <code>total</code> have same value, it should be different for each other depending on sum of product quantity  of each transaction.</p>
  
  <p><strong>Table</strong> <code>tb_penjualan</code>:
  <img src="https://i.stack.imgur.com/p1tn3.png" alt="tb_penjualan"></p>
  
  <p><strong>Table</strong>: <code>tb_detail_penjualan</code>:
  <img src="https://i.stack.imgur.com/91RQ9.png" alt="tb_detail_penjualan"></p>
  
  <p><strong>Output</strong>:
  <img src="https://i.stack.imgur.com/JMZrR.png" alt="order history"></p>
  
  <p><strong>Code</strong>:</p>
  
  <pre><code>&lt;?php
  $id_pelanggan=$_SESSION['user_session'];
  $query="SELECT  tb_penjualan.*, tb_pelanggan.nama_dpn, tb_pelanggan.nama_blk
      FROM tb_penjualan LEFT JOIN tb_pelanggan
      ON tb_penjualan.id_pelanggan=tb_pelanggan.id_pelanggan
      WHERE tb_penjualan.id_pelanggan=:id_pelanggan
      AND tb_penjualan.checkout='yes' ORDER BY id_penjualan";
  $stmt=$con-&gt;prepare($query);
  $stmt-&gt;execute(array(":id_pelanggan"=&gt;$id_pelanggan));
  $row=$stmt-&gt;fetch(PDO::FETCH_ASSOC);
  $id_penjualan=$row['id_penjualan'];
  if($stmt-&gt;rowCount()&gt;0)
  {
  $query2="SELECT SUM(subtotal) AS total, SUM(jumlah) as total_jml
       FROM tb_detail_penjualan
       WHERE id_penjualan=:id_penjualan";
  $stmt2=$con-&gt;prepare($query2);
  $stmt2-&gt;execute(array(":id_penjualan"=&gt;$id_penjualan));
  $stmt2-&gt;execute();
  $row2=$stmt2-&gt;fetch(PDO::FETCH_ASSOC);
  $no=1;
  while($row=$stmt-&gt;fetch(PDO::FETCH_ASSOC))
  {?&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $no++;?&gt;&lt;/td&gt;
      &lt;td&gt; &lt;?php echo $row['id_penjualan'] ;?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['nama_dpn'] ;?&gt;&amp;nbsp;&lt;?php echo $row['nama_blk'] ;?&gt; &lt;/td&gt;
      &lt;td&gt;&lt;?php echo date('d F y', strtotime($row['tanggal_blj'])); ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row2['total_jml']; ?&gt;&lt;/td&gt;
      &lt;td&gt; &lt;?php $harga = $row2['total'] ?&gt; &lt;?php echo "Rp. " .number_format($harga, 0, ',', '.');?&gt;&lt;/td&gt;
      &lt;td&gt;Rp. &lt;/td&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php   
  }
  } else { ?&gt;
      &lt;p&gt;Order history empty&lt;/p&gt;
  &lt;?php }?&gt;
  &lt;/tbody&gt;
  </code></pre>