Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
menggunkan while dengan multi query
$query=mysql_query("SELECT a.toko_code as code,a.nama_toko as nama,substring(a.nm_organ4,-4,3) as am,substring(a.nm_organ5,-4,3) as s,b.prdcd as plu FROM $pilih b JOIN $mtoko a ON b.shop=a.toko_code where a.nama_toko like '%$nama%' and b.prdcd='$cari' and b.tanggal between '$tanggal_awal' and '$tanggal_akhir' union
SELECT a.toko_code as code,a.nama_toko as nama,substring(a.nm_organ4,-4,3) as am,substring(a.nm_organ5,-4,3) as s, b.prdcd as plu FROM $pilih1 b JOIN $mtoko a ON b.shop=a.toko_code where a.nama_toko like '%$nama%' and b.prdcd='$cari' and b.tanggal between '$tanggal_awal_1' and '$tanggal_akhir_1' union
SELECT a.toko_code as code,a.nama_toko as nama,substring(a.nm_organ4,-4,3) as am,substring(a.nm_organ5,-4,3) as s, b.prdcd as plu FROM $pilih2 b JOIN $mtoko a ON b.shop=a.toko_code where a.nama_toko like '%$nama%' and b.prdcd='$cari' and b.tanggal between '$tanggal_awal_2' and '$tanggal_akhir_2'group by prdcd,shop");
$jumlah =mysql_fetch_array(mysql_query("SELECT avg(b.sls_qty) as spd1 FROM $pilih b JOIN $mtoko a ON b.shop=a.toko_code where a.nama_toko like '%$nama%' and b.prdcd='$cari' and b.tanggal between '$tanggal_awal' and '$tanggal_akhir' group by shop,prdcd"));
$jumlah1 =mysql_fetch_array(mysql_query("SELECT avg(b.sls_qty) as spd2 FROM $pilih1 b JOIN $mtoko a ON b.shop=a.toko_code where a.nama_toko like '%$nama%' and b.prdcd='$cari' and b.tanggal between '$tanggal_awal_1' and '$tanggal_akhir_1' group by shop,prdcd"));
$jumlah2 =mysql_fetch_array(mysql_query("SELECT avg(b.sls_qty) as spd3 FROM $pilih2 b JOIN $mtoko a ON a.toko_code=b.shop where a.nama_toko like '%$nama%' and b.prdcd='$cari' and b.tanggal between '$tanggal_awal_2' and'$tanggal_akhir_2' group by shop,prdcd"));
$hasil = 'hsl';
$hasil = ($jumlah['spd1']+$jumlah1['spd2']+$jumlah2['spd3']);
switch ($hasil) {
case ($jumlah > 0 && $jumlah1 > 0 && $jumlah2 > 0):
$hasil = ($jumlah['spd1']+$jumlah1['spd2']+$jumlah2['spd3'])/3;
break;
case ($jumlah == 0 && $jumlah1 > 0 && $jumlah2 > 0):
$hasil = ($jumlah1['spd2']+$jumlah2['spd3'])/2;
break;
case ($jumlah == 0 && $jumlah1 == 0 && $jumlah2 > 0):
$hasil = ($jumlah2['spd3']);
break;
case ($jumlah >0 && $jumlah1 > 0 && $jumlah2 == 0):
$hasil = ($jumlah['spd1']+$jumlah1['spd2'])/2;
break;
case ($jumlah >0 && $jumlah1 ==0 && $jumlah2 == 0):
$hasil = ($jumlah['spd1']);
break;
case ($jumlah ==0 && $jumlah1 > 0 && $jumlah2 == 0):
$hasil = ($jumlah1['spd2']);
break;
case ($jumlah >0 && $jumlah1 == 0 && $jumlah2 > 0):
$hasil = ($jumlah['spd1']+$jumlah2['spd3'])/2;
break;
}
if($query=== false) { die(mysql_error()); }
?>
<?php
}
?>
</p>
<table name="rohim" width="600" border="2" align="center" cellpadding="5" cellspacing="0">
<tr bgcolor="#FF6600">
<th width="200px" colspan="6"> Periode</th>
<th colspan="4">Rata-Rata</th>
</tr>
<tr align="center">
<th>No</th>
<th>Toko</th>
<th width="100px">Nama Toko</th>
<th>AM</th>
<th>AS</th>
<th>PLU</th>
<th><?php echo $sp1 ?></th>
<th><?php echo $sp2 ?></th>
<th><?php echo $sp3 ?></th>
<th>Average</th>
</tr>
<?php
//untuk penomoran data
$no=0;
//menampilkan pencarian data
while($row=mysql_fetch_array($query) && ($jumlah) && ($jumlah1) && ($jumlah2) && ($hasil)){
?>
<tr>
<td align="center" valign="center"><?php echo $no=$no+1; ?></td>
<td align="center"><?php echo $row['code'];?></td>
<td valign="center" align="center" width="100px"><?php echo $row['nama']; ?></td>
<td valign="center" align="center"><?php echo $row['am']; ?></td>
<td valign="center" align="center"><?php echo $row['s']; ?></td>
<td valign="center" align="center"><?php echo $row['plu'];?></td>
<td width="80" align="center"><?php echo number_format($row['spd1'],2);?></td>
<td width="80" align="center"><?php echo number_format($row['spd2'],2);?></td>
<td width="80" align="center"><?php echo number_format($row['spd3'],2);?></td>
<td width="80" align="center"><?php echo number_format($row['hsl'],2);?></td>
</tr>
<?php
}
?>
adakah solusi yang terbaik ya ? kasih saran kakak :D
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban