Advertisement
ekookda

syntaxnya

Jun 29th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.05 KB | None | 0 0
  1. [script form pertama]
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5.    <head>
  6.       <meta charset="utf-8">
  7.       <title>Form Pertama</title>
  8.    </head>
  9.    <body>
  10.       <form action="form_kedua.php" method="post" role="form">
  11.          <label for="n">Masukkan banyaknya jenis barang yang dibeli: </label>
  12.          <input type="number" name="banyaknya" id="n">
  13.          <input type="submit" name="submit_pertama" value="SUBMIT!">
  14.       </form>
  15.    </body>
  16. </html>
  17.  
  18.  
  19.  
  20.  
  21.  
  22. [form kedua]
  23.  
  24. <?php
  25.  
  26. if (isset($_POST['submit_pertama'])) {
  27.    // print_r($_POST);
  28.  
  29.    $n = $_POST['banyaknya'];
  30.    echo "<table>";
  31.       echo "<form role='form' method='post' action='output.php'>";
  32.  
  33.       for ($i=0; $i<=($n-1); $i++) {
  34.          echo "
  35.            <tr>
  36.               <td><label for='kodeBarang$i'>Barang ke-".($i+1)."</label></td>
  37.               <td><input type='text' id='kodeBarang$i' name='kodeBarang$i' placeholder='Masukkan Kode Barang' /></td>
  38.               <td><input type='number' id='jmlBarang$i' name='jmlBarang$i' placeholder='Jumlah Barang' /></td>
  39.            </tr>
  40.         ";
  41.  
  42.       }
  43.          echo "
  44.            <tr>
  45.               <td colspan='1'></td>
  46.               <td><input type='submit' id='submit' name='submit' value='Submit Barang' /></td>
  47.               <td><input type='hidden' name='hidden_submit' value='$n' /></td>
  48.            </tr>
  49.         ";
  50.       echo "</form>";
  51.    echo "</table>";
  52.  
  53. }
  54.  
  55.  
  56.  
  57. [output]
  58.  
  59.  
  60. <?php
  61.  
  62.  
  63.  
  64. // echo "<pre>";
  65. // print_r($data);
  66. // echo "</pre>";
  67.  
  68. if (isset($_POST['submit'])) {
  69.    $n = $_POST['hidden_submit'];
  70.    $data_barang = 10;
  71.  
  72.    // Data Barang
  73.    $data = array(
  74.                array('1001', 'Sabun Lifebouy', '1500'),
  75.                array('1002', 'Permen Blaster', '5600'),
  76.                array('1003', 'Pasta Gigi Pespodent', '4560'),
  77.                array('1004', 'Madu Arbain', '30000'),
  78.                array('1005', 'Kecap ABC', '7250'),
  79.                array('1006', 'Saus Tomat ABC', '6700'),
  80.                array('1007', 'Gula Gulaku', '8900'),
  81.                array('1008', 'Rinso', '7100'),
  82.                array('1009', 'Super Pel', '6450'),
  83.                array('1010', 'Permen Tango', '5600')
  84.    );
  85.  
  86.    echo "
  87.      <!DOCTYPE html>
  88.      <html>
  89.         <head>
  90.            <meta charset=\"utf-8\">
  91.            <title>output</title>
  92.         </head>
  93.         <body>
  94.   ";
  95.    echo "<h3>Daftar Harga Barang</h3>";
  96.    echo "<table border='1'>";
  97.    echo "<tr>";
  98.    echo "<th>No.</th>";
  99.    echo "<th>Kode Barang</th>";
  100.    echo "<th>Nama Barang</th>";
  101.    echo "<th>Harga</th>";
  102.    echo "</tr>";
  103.    for ($x=0; $x < count($data); $x++) {
  104.       echo "<tr>";
  105.       echo "<td>".($x+1)."</td>";
  106.       for ($y=0; $y < $n; $y++) {
  107.          echo "<td>".$data[$x][$y]."</td>";
  108.       }
  109.       echo "</tr>";
  110.    }
  111.    echo "</table>";
  112.  
  113.    // ambil nilai dari form
  114.    for ($i=0; $i<=($n-1); $i++) {
  115.       $kodeBarang[$i]  = $_POST['kodeBarang'.$i];
  116.       $jmlBarang[$i]   = $_POST['jmlBarang'.$i];
  117.    }
  118.  
  119.    echo "<h3>Daftar barang yang dibeli</h3>";
  120.  
  121.  
  122.  
  123. ?>
  124.    </body>
  125. </html>
  126.  
  127. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement