Postingan lainnya
Penyerdehanaan Dalam Menulis Kode
Selamat malam mas saya menulis kode tapi masalahnya itu panjang banget apakah bisa dibuat seingkat
$jan1 = $tgl."-09-01";
$jan2 = $tgl."-09-31";
$p20 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu20'");
$p21 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu21'");
$p22 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu22'");
$p24 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu24'");
$p26 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu26'");
$p28 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu28'");
$p29 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu29'");
$p30 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu30'");
$p34 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu34'");
$p35 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu35'");
$p36 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu36'");
$p37 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu37'");
$p38 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu38'");
$p39 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu39'");
$p40 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu40'");
$p41 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu41'");
$p42 = mysql_query ("SELECT * FROM jam_har WHERE tanggal BETWEEN '$jan1' AND '$jan2' AND barang = 'bu42'");
while($p20 = mysql_fetch_array($p20)){
$jan20[] = $p20['har'];
}while($p21 = mysql_fetch_array($p21)){
$jan20[] = $p20['har'];
/////dan seterusnya
4 Jawaban:
Jawaban Terpilih
<pre> $jan1 = $tgl."-09-01"; $jan2 = $tgl."-09-31"; $bu=42; function query($argv,$argv2,$argv3) { $query=mysql_query("SELECT * FROM jam_har WHERE tanggal BETWEEN '$argv' AND '$argv2' AND barang = '$argv3'"); } query($jan1,$jan2,'bu'.$bu); </pre> sudah belajar function dan looping?
muantap jiwa mas, terimkasih mas saca coba terapkan dulu mas. maaf mas saya belum belajar. saya langsung kerjakan klo ada masalah baru saya otak atik kesalahanya mas, otodidak juga soalnya mas, saya bingun klo belajar dg metode seperti apa. soalnya tidak ada yg bimbing, maklum cari murah mas. terimakasih juga mas sebelumnya...
oke sama sama, saya juga otodidak soalnya, hehehe. banyak cari refrensi di php.net atau stackoverflow.com
siap mas, tapi kebanyakan basaha luar agak ribet hehe ngerti dikit2 sih...