justhrun

barang_revolut.pehape

Aug 31st, 2014
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2. // ########### CARA 1 ##############
  3.     $sql = "select kodebarang, namabarang, sum(jumlah) as jumlah
  4.            from barang group by namabarang order by kodebarang asc";
  5.     $datatamu = mysqli_query($con,$sql) or die("Gagal :".mysql_error());
  6.     echo "<table width='100%' align='center' border='1'>
  7.        <tr>
  8.            <th>Kode Barang</th>
  9.            <th>Nama Barang</th>
  10.            <th>Jumlah</th>
  11.    </tr>\n";
  12.     while($rec=mysqli_fetch_array($datatamu)) {
  13.         echo "<tr>
  14.        <td>". $rec["kodebarang"] ."</td>
  15.        <td>". $rec["namabarang"] ."</td>
  16.        <td>". $rec["jumlah"] ."</td></tr>\n";
  17.     }
  18.     echo "</table>\n";
  19.     mysqli_free_result($datamu);
  20.     mysqli_close($con);
  21. ?>
  22.  
  23. <?php
  24. // ########### CARA 2 ##############
  25.     $sql = "select kodebarang, namabarang, sum(jumlah) as jumlah
  26.            from barang group by namabarang order by kodebarang asc";
  27.     $datatamu = mysqli_query($con,$sql) or die("Gagal :".mysql_error());
  28.     echo "<table width='100%' align='center' border='1'>
  29.        <tr>
  30.            <th>Kode Barang</th>
  31.            <th>Nama Barang</th>
  32.            <th>Jumlah</th>
  33.    </tr>\n";
  34.     while(list($kodebarang,$namabarang,$jumlah)=mysqli_fetch_row($datatamu)) {
  35.         echo "<tr>
  36.        <td>$kodebarang</td>
  37.        <td>$namabarang</td>
  38.        <td>$jumlah</td></tr>\n";
  39.     }
  40.     echo "</table>\n";
  41.     mysqli_free_result($datamu);
  42.     mysqli_close($con);
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment