Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ########### CARA 1 ##############
- $sql = "select kodebarang, namabarang, sum(jumlah) as jumlah
- from barang group by namabarang order by kodebarang asc";
- $datatamu = mysqli_query($con,$sql) or die("Gagal :".mysql_error());
- echo "<table width='100%' align='center' border='1'>
- <tr>
- <th>Kode Barang</th>
- <th>Nama Barang</th>
- <th>Jumlah</th>
- </tr>\n";
- while($rec=mysqli_fetch_array($datatamu)) {
- echo "<tr>
- <td>". $rec["kodebarang"] ."</td>
- <td>". $rec["namabarang"] ."</td>
- <td>". $rec["jumlah"] ."</td></tr>\n";
- }
- echo "</table>\n";
- mysqli_free_result($datamu);
- mysqli_close($con);
- ?>
- <?php
- // ########### CARA 2 ##############
- $sql = "select kodebarang, namabarang, sum(jumlah) as jumlah
- from barang group by namabarang order by kodebarang asc";
- $datatamu = mysqli_query($con,$sql) or die("Gagal :".mysql_error());
- echo "<table width='100%' align='center' border='1'>
- <tr>
- <th>Kode Barang</th>
- <th>Nama Barang</th>
- <th>Jumlah</th>
- </tr>\n";
- while(list($kodebarang,$namabarang,$jumlah)=mysqli_fetch_row($datatamu)) {
- echo "<tr>
- <td>$kodebarang</td>
- <td>$namabarang</td>
- <td>$jumlah</td></tr>\n";
- }
- echo "</table>\n";
- mysqli_free_result($datamu);
- mysqli_close($con);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment