Postingan lainnya
Bagaimana membuat IF(isset()) dengan kondisi didalam nya ada 2 query?
Saya mempunyai fungsi filter didalam halaman web saya. Untuk fungsi filter sudah berhasil jalan dimana berhasil jalan apabila variabel ditetapkan dengan dropdown list nama sekolah dan menetapkan tanggal nya. Berikut adalah codingan penetapan value variable nya
<form action="" method="post" id="form-rekap" name="form-rekap">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-4">
<div class="form-group">
<div class='input-group date'>
<input id="" type="date" name="tgl1" value="<?php echo $tanggal=date('d/m/Y'); ?>" class="form-control">
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<div align="center">
<h6>S/D</h6>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<div class='input-group date'>
<input id="" type="date" name="tgl2" value="<?php echo $tanggal=date('d/m/Y'); ?>" class="form-control">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<div class="form-group">
<div class='input-group date'>
<select class="bootstrap-select" name="nm_sekolah">
<option value="Error !! Belum Memilih Nama Lembaga !" selected="selected">Pilih Lembaga</option>
<?php
$query=mysql_query("SELECT a.*, b.nm_kecamatan AS nm_kecamatan, c.nm_sekolah AS nm_sekolah
FROM sekolah a
JOIN kecamatan b ON a.id_kecamatan = b.id_kecamatan
JOIN sekolah c ON a.id_sekolah = c.id_sekolah
ORDER BY id_kecamatan ASC",$connect);
while($data=mysql_fetch_array($query))
{
?>
<option value="<?php echo $data['id_sekolah']; ?>"><?php echo $data['nm_sekolah']; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group" align="center">
<div class="btn-group" role="group">
<button id="form-rekap" name="form-rekap" type="submit"class="btn btn-default font-icon font-icon-server" data-toggle="tooltip" data-placement="top" title="Rekap?"></button>
</div>
</div>
</div>
</div>
</form>
yang jadi permasalahan saya adalah bagaimana saya menggunakan IF(isset()) dengan 2 kondisi query didalam nya?
karena dimana kondisi pertama adalah jika varibel $nm_sekolah =$_ POST['nm_sekolah] ; $tgl1=$_ POST['tgl1']; dan $tgl2=$_POST['tgl2']; ditetapkan dengan codingan diatas maka akan menampilkan hasil sesuai value yang ditetapkan
dan kondisi ke 2 adalah saat pertama kali halaman dibuka, maka akan menampilkan keseluruhan data tanpa kondisi WHERE id_ sekolah = $id_ sekolah tetapi tanggal dimulai dari tanggal 1 bulan saat ini dan berakhir tanggal akhir bulan saat ini.
berikut adalah codingan saya tetapi tidak berjalan atau masih ada kesalahan
<tbody>
<?php
//untuk option
$tgl1=$_POST['tgl1'];
$tgl2=$_POST['tgl2'];
$nm_sekolah=$_POST['nm_sekolah'];
if (isset($_POST['nm_sekolah']) && isset($_POST['tgl1']) && isset($_POST['tgl2'])){
$sql = mysql_query("SELECT a.*, b.nm_kecamatan AS nm_kecamatan, c.nm_sekolah AS nm_sekolah
FROM keadaan_siswa a
JOIN kecamatan b ON a.id_kecamatan = b.id_kecamatan
JOIN sekolah c ON a.id_sekolah = c.id_sekolah
WHERE a.id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2'
ORDER BY id_kecamatan ASC");
while ($data = mysql_fetch_assoc($sql))
{
?>
<tr>
<tr>
<td><center>VII</center></td>
<td><center>0</center></td>
<td><center><?php echo $data['bulan_lalu_laki_vii'];?></center></td>
<td><center><?php echo $data['bulan_lalu_perempuan_vii'];?></center></td>
<th><center><?php echo $data['bulan_lalu_laki_vii']+$data['bulan_lalu_perempuan_vii'];?></center></th>
<td><center><?php echo $data['keluar_laki_vii'];?></center></td>
<td><center><?php echo $data['keluar_perempuan_vii'];?></center></td>
<td><center><?php echo $data['masuk_laki_vii'];?></center></td>
<td><center><?php echo $data['masuk_perempuan_vii'];?></center></td>
<td><center><?php echo $data['bulan_ini_laki_vii'];?></center></td>
<td><center><?php echo $data['bulan_ini_perempuan_vii'];?></center></td>
<th><center><?php echo $data['bulan_ini_laki_vii']+$data['bulan_ini_perempuan_vii'];?></center></th>
<?php
$sql1 = mysql_query("SELECT a.*, b.nm_kecamatan AS nm_kecamatan, c.nm_sekolah AS nm_sekolah,
IFNULL(sum(a.agama_siswa='Islam' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_islam_vii, IFNULL(sum(a.agama_siswa='Protestan' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_protestan_vii, IFNULL(sum(a.agama_siswa='Katolik' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_katolik_vii, IFNULL(sum(a.agama_siswa='Buddha' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_buddha_vii, IFNULL(sum(a.agama_siswa='Hindu' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_hindu_vii, IFNULL(sum(a.agama_siswa='Konghucu' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_konghucu_vii,
IFNULL(sum(a.agama_siswa='Islam' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_islam_viii, IFNULL(sum(a.agama_siswa='Protestan' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_protestan_viii, IFNULL(sum(a.agama_siswa='Katolik' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_katolik_viii, IFNULL(sum(a.agama_siswa='Buddha' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_buddha_viii, IFNULL(sum(a.agama_siswa='Hindu' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_hindu_viii, IFNULL(sum(a.agama_siswa='Konghucu' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_konghucu_viii,
IFNULL(sum(a.agama_siswa='Islam' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_islam_ix, IFNULL(sum(a.agama_siswa='Protestan' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_protestan_ix, IFNULL(sum(a.agama_siswa='Katolik' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_katolik_ix, IFNULL(sum(a.agama_siswa='Buddha' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_buddha_ix, IFNULL(sum(a.agama_siswa='Hindu' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_hindu_ix, IFNULL(sum(a.agama_siswa='Konghucu' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_konghucu_ix
FROM siswa a
JOIN kecamatan b ON a.id_kecamatan = b.id_kecamatan
JOIN sekolah c ON a.id_sekolah = c.id_sekolah
WHERE a.id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2'");
while ($data1 = mysql_fetch_assoc($sql1))
{
?>
<td><center><?php echo $data1['agama_siswa_islam_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_protestan_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_katolik_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_buddha_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_hindu_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_konghucu_vii'];?></center></td>
<th><center><?php echo $data1['agama_siswa_islam_vii']+$data1['agama_siswa_protestan_vii']+$data1['agama_siswa_katolik_vii']+$data1['agama_siswa_buddha_vii']+$data1['agama_siswa_hindu_vii']+$data1['agama_siswa_konghucu_vii'];?></center></th>
<?php
$sql_umur = mysql_query("SELECT
COUNT(IF(a.umur <=11,1,NULL)) AS umur11,
COUNT(IF(a.umur=12,1,NULL)) AS umur12,
COUNT(IF(a.umur=13,1,NULL)) AS umur13,
COUNT(IF(a.umur=14,1,NULL)) AS umur14,
COUNT(IF(a.umur=15,1,NULL)) AS umur15,
COUNT(IF(a.umur=16,1,NULL)) AS umur16,
COUNT(IF(a.umur>=17,1,NULL)) AS umur17
FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE())
AS umur
FROM siswa
WHERE (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')
AND id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2') a");
while ($data_umur = mysql_fetch_assoc($sql_umur))
{
?>
<td><center><?php echo $data_umur['umur11'];?></center></td>
<td><center><?php echo $data_umur['umur12'];?></center></td>
<td><center><?php echo $data_umur['umur13'];?></center></td>
<td><center><?php echo $data_umur['umur14'];?></center></td>
<td><center><?php echo $data_umur['umur15'];?></center></td>
<td><center><?php echo $data_umur['umur16'];?></center></td>
<td><center><?php echo $data_umur['umur17'];?></center></td>
<th><center><?php echo $data_umur['umur11']+$data_umur['umur12']+$data_umur['umur13']+$data_umur['umur14']+$data_umur['umur15']+$data_umur['umur16']+$data_umur['umur17'];?></center></th>
<?php
}
?>
</tr>
<tr>
<td><center>VIII</center></td>
<td><center>0</center></td>
<td><center><?php echo $data['bulan_lalu_laki_viii'];?></center></td>
<td><center><?php echo $data['bulan_lalu_perempuan_viii'];?></center></td>
<th><center><?php echo $data['bulan_lalu_laki_viii']+$data['bulan_lalu_perempuan_viii'];?></center></th>
<td><center><?php echo $data['keluar_laki_viii'];?></center></td>
<td><center><?php echo $data['keluar_perempuan_viii'];?></center></td>
<td><center><?php echo $data['masuk_laki_viii'];?></center></td>
<td><center><?php echo $data['masuk_perempuan_viii'];?></center></td>
<td><center><?php echo $data['bulan_ini_laki_viii'];?></center></td>
<td><center><?php echo $data['bulan_ini_perempuan_viii'];?></center></td>
<th><center><?php echo $data['bulan_ini_laki_viii']+$data['bulan_ini_perempuan_viii'];?></center></th>
<td><center><?php echo $data1['agama_siswa_islam_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_protestan_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_katolik_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_buddha_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_hindu_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_konghucu_viii'];?></center></td>
<th><center><?php echo $data1['agama_siswa_islam_viii']+$data1['agama_siswa_protestan_viii']+$data1['agama_siswa_katolik_viii']+$data1['agama_siswa_buddha_viii']+$data1['agama_siswa_hindu_viii']+$data1['agama_siswa_konghucu_viii'];?></center></th>
<?php
$sql_umur = mysql_query("SELECT
COUNT(IF(a.umur <=11,1,NULL)) AS umur11,
COUNT(IF(a.umur=12,1,NULL)) AS umur12,
COUNT(IF(a.umur=13,1,NULL)) AS umur13,
COUNT(IF(a.umur=14,1,NULL)) AS umur14,
COUNT(IF(a.umur=15,1,NULL)) AS umur15,
COUNT(IF(a.umur=16,1,NULL)) AS umur16,
COUNT(IF(a.umur>=17,1,NULL)) AS umur17
FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE())
AS umur FROM siswa
WHERE (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')
AND id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2') a");
while ($data_umur = mysql_fetch_assoc($sql_umur))
{
?>
<td><center><?php echo $data_umur['umur11'];?></center></td>
<td><center><?php echo $data_umur['umur12'];?></center></td>
<td><center><?php echo $data_umur['umur13'];?></center></td>
<td><center><?php echo $data_umur['umur14'];?></center></td>
<td><center><?php echo $data_umur['umur15'];?></center></td>
<td><center><?php echo $data_umur['umur16'];?></center></td>
<td><center><?php echo $data_umur['umur17'];?></center></td>
<th><center><?php echo $data_umur['umur11']+$data_umur['umur12']+$data_umur['umur13']+$data_umur['umur14']+$data_umur['umur15']+$data_umur['umur16']+$data_umur['umur17'];?></center></th>
<?php
}
?>
</tr>
<tr>
<td><center>IX</center></td>
<td><center>0</center></td>
<td><center><?php echo $data['bulan_lalu_laki_ix'];?></center></td>
<td><center><?php echo $data['bulan_lalu_perempuan_ix'];?></center></td>
<th><center><?php echo $data['bulan_lalu_laki_ix']+$data['bulan_lalu_perempuan_ix'];?></center></th>
<td><center><?php echo $data['keluar_laki_ix'];?></center></td>
<td><center><?php echo $data['keluar_perempuan_ix'];?></center></td>
<td><center><?php echo $data['masuk_laki_ix'];?></center></td>
<td><center><?php echo $data['masuk_perempuan_ix'];?></center></td>
<td><center><?php echo $data['bulan_ini_laki_ix'];?></center></td>
<td><center><?php echo $data['bulan_ini_perempuan_ix'];?></center></td>
<th><center><?php echo $data['bulan_ini_laki_ix']+$data['bulan_ini_perempuan_ix'];?></center></th>
<td><center><?php echo $data1['agama_siswa_islam_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_protestan_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_katolik_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_buddha_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_hindu_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_konghucu_ix'];?></center></td>
<th><center><?php echo $data1['agama_siswa_islam_ix']+$data1['agama_siswa_protestan_ix']+$data1['agama_siswa_katolik_ix']+$data1['agama_siswa_buddha_ix']+$data1['agama_siswa_hindu_ix']+$data1['agama_siswa_konghucu_ix'];?></center></th>
<?php
$sql_umur = mysql_query("SELECT
COUNT(IF(a.umur <=11,1,NULL)) AS umur11,
COUNT(IF(a.umur=12,1,NULL)) AS umur12,
COUNT(IF(a.umur=13,1,NULL)) AS umur13,
COUNT(IF(a.umur=14,1,NULL)) AS umur14,
COUNT(IF(a.umur=15,1,NULL)) AS umur15,
COUNT(IF(a.umur=16,1,NULL)) AS umur16,
COUNT(IF(a.umur>=17,1,NULL)) AS umur17
FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE())
AS umur
FROM siswa
WHERE (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')
AND id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2') a");
while ($data_umur = mysql_fetch_assoc($sql_umur))
{
?>
<td><center><?php echo $data_umur['umur11'];?></center></td>
<td><center><?php echo $data_umur['umur12'];?></center></td>
<td><center><?php echo $data_umur['umur13'];?></center></td>
<td><center><?php echo $data_umur['umur14'];?></center></td>
<td><center><?php echo $data_umur['umur15'];?></center></td>
<td><center><?php echo $data_umur['umur16'];?></center></td>
<td><center><?php echo $data_umur['umur17'];?></center></td>
<th><center><?php echo $data_umur['umur11']+$data_umur['umur12']+$data_umur['umur13']+$data_umur['umur14']+$data_umur['umur15']+$data_umur['umur16']+$data_umur['umur17'];?></center></th>
<?php
}
?>
</tr>
</tr>
<?php
}
}
}else{
$sql = mysql_query("SELECT a.*, b.nm_kecamatan AS nm_kecamatan, c.nm_sekolah AS nm_sekolah
FROM keadaan_siswa a
JOIN kecamatan b ON a.id_kecamatan = b.id_kecamatan
JOIN sekolah c ON a.id_sekolah = c.id_sekolah
WHERE tanggal_data BETWEEN '$tgl1' AND '$tgl2'
ORDER BY id_kecamatan ASC");
while ($data = mysql_fetch_assoc($sql))
{
?>
<tr>
<tr>
<td><center>VII</center></td>
<td><center>0</center></td>
<td><center><?php echo $data['bulan_lalu_laki_vii'];?></center></td>
<td><center><?php echo $data['bulan_lalu_perempuan_vii'];?></center></td>
<th><center><?php echo $data['bulan_lalu_laki_vii']+$data['bulan_lalu_perempuan_vii'];?></center></th>
<td><center><?php echo $data['keluar_laki_vii'];?></center></td>
<td><center><?php echo $data['keluar_perempuan_vii'];?></center></td>
<td><center><?php echo $data['masuk_laki_vii'];?></center></td>
<td><center><?php echo $data['masuk_perempuan_vii'];?></center></td>
<td><center><?php echo $data['bulan_ini_laki_vii'];?></center></td>
<td><center><?php echo $data['bulan_ini_perempuan_vii'];?></center></td>
<th><center><?php echo $data['bulan_ini_laki_vii']+$data['bulan_ini_perempuan_vii'];?></center></th>
<?php
$sql1 = mysql_query("SELECT a.*, b.nm_kecamatan AS nm_kecamatan, c.nm_sekolah AS nm_sekolah,
IFNULL(sum(a.agama_siswa='Islam' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_islam_vii, IFNULL(sum(a.agama_siswa='Protestan' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_protestan_vii, IFNULL(sum(a.agama_siswa='Katolik' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_katolik_vii, IFNULL(sum(a.agama_siswa='Buddha' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_buddha_vii, IFNULL(sum(a.agama_siswa='Hindu' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_hindu_vii, IFNULL(sum(a.agama_siswa='Konghucu' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_konghucu_vii,
IFNULL(sum(a.agama_siswa='Islam' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_islam_viii, IFNULL(sum(a.agama_siswa='Protestan' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_protestan_viii, IFNULL(sum(a.agama_siswa='Katolik' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_katolik_viii, IFNULL(sum(a.agama_siswa='Buddha' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_buddha_viii, IFNULL(sum(a.agama_siswa='Hindu' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_hindu_viii, IFNULL(sum(a.agama_siswa='Konghucu' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_konghucu_viii,
IFNULL(sum(a.agama_siswa='Islam' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_islam_ix, IFNULL(sum(a.agama_siswa='Protestan' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_protestan_ix, IFNULL(sum(a.agama_siswa='Katolik' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_katolik_ix, IFNULL(sum(a.agama_siswa='Buddha' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_buddha_ix, IFNULL(sum(a.agama_siswa='Hindu' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_hindu_ix, IFNULL(sum(a.agama_siswa='Konghucu' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_konghucu_ix
FROM siswa a
JOIN kecamatan b ON a.id_kecamatan = b.id_kecamatan
JOIN sekolah c ON a.id_sekolah = c.id_sekolah
WHERE tanggal_data BETWEEN '$tgl1' AND '$tgl2'");
while ($data1 = mysql_fetch_assoc($sql1))
{
?>
<td><center><?php echo $data1['agama_siswa_islam_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_protestan_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_katolik_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_buddha_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_hindu_vii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_konghucu_vii'];?></center></td>
<th><center><?php echo $data1['agama_siswa_islam_vii']+$data1['agama_siswa_protestan_vii']+$data1['agama_siswa_katolik_vii']+$data1['agama_siswa_buddha_vii']+$data1['agama_siswa_hindu_vii']+$data1['agama_siswa_konghucu_vii'];?></center></th>
<?php
$sql_umur = mysql_query("SELECT
COUNT(IF(a.umur <=11,1,NULL)) AS umur11,
COUNT(IF(a.umur=12,1,NULL)) AS umur12,
COUNT(IF(a.umur=13,1,NULL)) AS umur13,
COUNT(IF(a.umur=14,1,NULL)) AS umur14,
COUNT(IF(a.umur=15,1,NULL)) AS umur15,
COUNT(IF(a.umur=16,1,NULL)) AS umur16,
COUNT(IF(a.umur>=17,1,NULL)) AS umur17
FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE())
AS umur
FROM siswa
WHERE (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')
AND tanggal_data BETWEEN '$tgl1' AND '$tgl2') a");
while ($data_umur = mysql_fetch_assoc($sql_umur))
{
?>
<td><center><?php echo $data_umur['umur11'];?></center></td>
<td><center><?php echo $data_umur['umur12'];?></center></td>
<td><center><?php echo $data_umur['umur13'];?></center></td>
<td><center><?php echo $data_umur['umur14'];?></center></td>
<td><center><?php echo $data_umur['umur15'];?></center></td>
<td><center><?php echo $data_umur['umur16'];?></center></td>
<td><center><?php echo $data_umur['umur17'];?></center></td>
<th><center><?php echo $data_umur['umur11']+$data_umur['umur12']+$data_umur['umur13']+$data_umur['umur14']+$data_umur['umur15']+$data_umur['umur16']+$data_umur['umur17'];?></center></th>
<?php
}
?>
</tr>
<tr>
<td><center>VIII</center></td>
<td><center>0</center></td>
<td><center><?php echo $data['bulan_lalu_laki_viii'];?></center></td>
<td><center><?php echo $data['bulan_lalu_perempuan_viii'];?></center></td>
<th><center><?php echo $data['bulan_lalu_laki_viii']+$data['bulan_lalu_perempuan_viii'];?></center></th>
<td><center><?php echo $data['keluar_laki_viii'];?></center></td>
<td><center><?php echo $data['keluar_perempuan_viii'];?></center></td>
<td><center><?php echo $data['masuk_laki_viii'];?></center></td>
<td><center><?php echo $data['masuk_perempuan_viii'];?></center></td>
<td><center><?php echo $data['bulan_ini_laki_viii'];?></center></td>
<td><center><?php echo $data['bulan_ini_perempuan_viii'];?></center></td>
<th><center><?php echo $data['bulan_ini_laki_viii']+$data['bulan_ini_perempuan_viii'];?></center></th>
<td><center><?php echo $data1['agama_siswa_islam_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_protestan_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_katolik_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_buddha_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_hindu_viii'];?></center></td>
<td><center><?php echo $data1['agama_siswa_konghucu_viii'];?></center></td>
<th><center><?php echo $data1['agama_siswa_islam_viii']+$data1['agama_siswa_protestan_viii']+$data1['agama_siswa_katolik_viii']+$data1['agama_siswa_buddha_viii']+$data1['agama_siswa_hindu_viii']+$data1['agama_siswa_konghucu_viii'];?></center></th>
<?php
$sql_umur = mysql_query("SELECT
COUNT(IF(a.umur <=11,1,NULL)) AS umur11,
COUNT(IF(a.umur=12,1,NULL)) AS umur12,
COUNT(IF(a.umur=13,1,NULL)) AS umur13,
COUNT(IF(a.umur=14,1,NULL)) AS umur14,
COUNT(IF(a.umur=15,1,NULL)) AS umur15,
COUNT(IF(a.umur=16,1,NULL)) AS umur16,
COUNT(IF(a.umur>=17,1,NULL)) AS umur17
FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE())
AS umur FROM siswa
WHERE (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')
AND tanggal_data BETWEEN '$tgl1' AND '$tgl2') a");
while ($data_umur = mysql_fetch_assoc($sql_umur))
{
?>
<td><center><?php echo $data_umur['umur11'];?></center></td>
<td><center><?php echo $data_umur['umur12'];?></center></td>
<td><center><?php echo $data_umur['umur13'];?></center></td>
<td><center><?php echo $data_umur['umur14'];?></center></td>
<td><center><?php echo $data_umur['umur15'];?></center></td>
<td><center><?php echo $data_umur['umur16'];?></center></td>
<td><center><?php echo $data_umur['umur17'];?></center></td>
<th><center><?php echo $data_umur['umur11']+$data_umur['umur12']+$data_umur['umur13']+$data_umur['umur14']+$data_umur['umur15']+$data_umur['umur16']+$data_umur['umur17'];?></center></th>
<?php
}
?>
</tr>
<tr>
<td><center>IX</center></td>
<td><center>0</center></td>
<td><center><?php echo $data['bulan_lalu_laki_ix'];?></center></td>
<td><center><?php echo $data['bulan_lalu_perempuan_ix'];?></center></td>
<th><center><?php echo $data['bulan_lalu_laki_ix']+$data['bulan_lalu_perempuan_ix'];?></center></th>
<td><center><?php echo $data['keluar_laki_ix'];?></center></td>
<td><center><?php echo $data['keluar_perempuan_ix'];?></center></td>
<td><center><?php echo $data['masuk_laki_ix'];?></center></td>
<td><center><?php echo $data['masuk_perempuan_ix'];?></center></td>
<td><center><?php echo $data['bulan_ini_laki_ix'];?></center></td>
<td><center><?php echo $data['bulan_ini_perempuan_ix'];?></center></td>
<th><center><?php echo $data['bulan_ini_laki_ix']+$data['bulan_ini_perempuan_ix'];?></center></th>
<td><center><?php echo $data1['agama_siswa_islam_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_protestan_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_katolik_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_buddha_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_hindu_ix'];?></center></td>
<td><center><?php echo $data1['agama_siswa_konghucu_ix'];?></center></td>
<th><center><?php echo $data1['agama_siswa_islam_ix']+$data1['agama_siswa_protestan_ix']+$data1['agama_siswa_katolik_ix']+$data1['agama_siswa_buddha_ix']+$data1['agama_siswa_hindu_ix']+$data1['agama_siswa_konghucu_ix'];?></center></th>
<?php
$sql_umur = mysql_query("SELECT
COUNT(IF(a.umur <=11,1,NULL)) AS umur11,
COUNT(IF(a.umur=12,1,NULL)) AS umur12,
COUNT(IF(a.umur=13,1,NULL)) AS umur13,
COUNT(IF(a.umur=14,1,NULL)) AS umur14,
COUNT(IF(a.umur=15,1,NULL)) AS umur15,
COUNT(IF(a.umur=16,1,NULL)) AS umur16,
COUNT(IF(a.umur>=17,1,NULL)) AS umur17
FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE())
AS umur
FROM siswa
WHERE (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')
AND tanggal_data BETWEEN '$tgl1' AND '$tgl2') a");
while ($data_umur = mysql_fetch_assoc($sql_umur))
{
?>
<td><center><?php echo $data_umur['umur11'];?></center></td>
<td><center><?php echo $data_umur['umur12'];?></center></td>
<td><center><?php echo $data_umur['umur13'];?></center></td>
<td><center><?php echo $data_umur['umur14'];?></center></td>
<td><center><?php echo $data_umur['umur15'];?></center></td>
<td><center><?php echo $data_umur['umur16'];?></center></td>
<td><center><?php echo $data_umur['umur17'];?></center></td>
<th><center><?php echo $data_umur['umur11']+$data_umur['umur12']+$data_umur['umur13']+$data_umur['umur14']+$data_umur['umur15']+$data_umur['umur16']+$data_umur['umur17'];?></center></th>
<?php
}
?>
</tr>
</tr>
<?php
}
}
}
?>
</tbody>
mohon bantuannya gan?
1 Jawaban:
<div>ubah cara pandangnya gan, ga semua harus if else panjang dan rumit.<br>kamu mau query pertama akses itu tampil semua karena belum pilih nm_sekolah kan?<br>cukup ubah querynya jadi gini aja.<br><br></div><pre><?php
//untuk option
$tgl1=$_POST['tgl1'];
$tgl2=$_POST['tgl2'];
$nm_sekolah=$_POST['nm_sekolah'];
$where_nm_sekolah = "";
if ($nm_sekolah != "") {
$where_nm_sekolah = "a.id_sekolah = '". $_POST['nm_sekolah'] ."' AND";
}
if (isset($_POST['tgl1']) &amp;&amp; isset($_POST['tgl2'])){
$sql = mysql_query("SELECT a.*, b.nm_kecamatan AS nm_kecamatan, c.nm_sekolah AS nm_sekolah
FROM keadaan_siswa a
JOIN kecamatan b ON a.id_kecamatan = b.id_kecamatan
JOIN sekolah c ON a.id_sekolah = c.id_sekolah
WHERE ". $where_nm_sekolah ." a.id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2'
ORDER BY id_kecamatan ASC");</pre><div><br>Ini full nya :</div><pre>&lt;tbody&gt;
&lt;?php
//untuk option
$tgl1=$_POST['tgl1'];
$tgl2=$_POST['tgl2'];
$nm_sekolah=$_POST['nm_sekolah'];
$where_nm_sekolah = "";
if ($nm_sekolah != "") {
$where_nm_sekolah = "a.id_sekolah = '". $_POST['nm_sekolah'] ."' AND";
}
if (isset($_POST['tgl1']) &amp;&amp; isset($_POST['tgl2']))
{
$sql = mysql_query("SELECT a.*, b.nm_kecamatan AS nm_kecamatan, c.nm_sekolah AS nm_sekolah
FROM keadaan_siswa a
JOIN kecamatan b ON a.id_kecamatan = b.id_kecamatan
JOIN sekolah c ON a.id_sekolah = c.id_sekolah
WHERE ". $where_nm_sekolah ." a.id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2'
ORDER BY id_kecamatan ASC");
while ($data = mysql_fetch_assoc($sql))
{
?&gt;
&lt;tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;center&gt;VII&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;0&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_lalu_laki_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_lalu_perempuan_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;&lt;?php echo $data['bulan_lalu_laki_vii']+$data['bulan_lalu_perempuan_vii'];?&gt;&lt;/center&gt;
&lt;/th&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['keluar_laki_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['keluar_perempuan_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['masuk_laki_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['masuk_perempuan_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_ini_laki_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_ini_perempuan_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;&lt;?php echo $data['bulan_ini_laki_vii']+$data['bulan_ini_perempuan_vii'];?&gt;&lt;/center&gt;
&lt;/th&gt;
&lt;?php
$sql1 = mysql_query("SELECT a.*, b.nm_kecamatan AS nm_kecamatan, c.nm_sekolah AS nm_sekolah,
IFNULL(sum(a.agama_siswa='Islam' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_islam_vii, IFNULL(sum(a.agama_siswa='Protestan' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_protestan_vii, IFNULL(sum(a.agama_siswa='Katolik' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_katolik_vii, IFNULL(sum(a.agama_siswa='Buddha' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_buddha_vii, IFNULL(sum(a.agama_siswa='Hindu' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_hindu_vii, IFNULL(sum(a.agama_siswa='Konghucu' AND (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')),0) AS agama_siswa_konghucu_vii,
IFNULL(sum(a.agama_siswa='Islam' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_islam_viii, IFNULL(sum(a.agama_siswa='Protestan' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_protestan_viii, IFNULL(sum(a.agama_siswa='Katolik' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_katolik_viii, IFNULL(sum(a.agama_siswa='Buddha' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_buddha_viii, IFNULL(sum(a.agama_siswa='Hindu' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_hindu_viii, IFNULL(sum(a.agama_siswa='Konghucu' AND (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')),0) AS agama_siswa_konghucu_viii,
IFNULL(sum(a.agama_siswa='Islam' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_islam_ix, IFNULL(sum(a.agama_siswa='Protestan' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_protestan_ix, IFNULL(sum(a.agama_siswa='Katolik' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_katolik_ix, IFNULL(sum(a.agama_siswa='Buddha' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_buddha_ix, IFNULL(sum(a.agama_siswa='Hindu' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_hindu_ix, IFNULL(sum(a.agama_siswa='Konghucu' AND (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')),0) AS agama_siswa_konghucu_ix
FROM siswa a
JOIN kecamatan b ON a.id_kecamatan = b.id_kecamatan
JOIN sekolah c ON a.id_sekolah = c.id_sekolah
WHERE a.id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2'");
while ($data1 = mysql_fetch_assoc($sql1))
{
?&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_islam_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_protestan_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_katolik_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_buddha_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_hindu_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_konghucu_vii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;
&lt;?php echo $data1['agama_siswa_islam_vii']+$data1['agama_siswa_protestan_vii']+$data1['agama_siswa_katolik_vii']+$data1['agama_siswa_buddha_vii']+$data1['agama_siswa_hindu_vii']+$data1['agama_siswa_konghucu_vii'];?&gt;
&lt;/center&gt;
&lt;/th&gt;
&lt;?php
$sql_umur = mysql_query("SELECT
COUNT(IF(a.umur &lt;=11,1,NULL)) AS umur11,
COUNT(IF(a.umur=12,1,NULL)) AS umur12,
COUNT(IF(a.umur=13,1,NULL)) AS umur13,
COUNT(IF(a.umur=14,1,NULL)) AS umur14,
COUNT(IF(a.umur=15,1,NULL)) AS umur15,
COUNT(IF(a.umur=16,1,NULL)) AS umur16,
COUNT(IF(a.umur&gt;=17,1,NULL)) AS umur17
FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE())
AS umur
FROM siswa
WHERE (rombel_siswa = 'VII-A' OR rombel_siswa = 'VII-B' OR rombel_siswa = 'VII-C' OR rombel_siswa = 'VII-D' OR rombel_siswa = 'VII-E' OR rombel_siswa = 'VII-F' OR rombel_siswa = 'VII-G' OR rombel_siswa = 'VII-H' OR rombel_siswa = 'VII-I' OR rombel_siswa = 'VII-J' OR rombel_siswa = 'VII-K' OR rombel_siswa = 'VII-L' OR rombel_siswa = 'VII-M' OR rombel_siswa = 'VII-N' OR rombel_siswa = 'VII-O')
AND id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2') a");
while ($data_umur = mysql_fetch_assoc($sql_umur))
{
?&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur11'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur12'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur13'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur14'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur15'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur16'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur17'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;
&lt;?php echo $data_umur['umur11']+$data_umur['umur12']+$data_umur['umur13']+$data_umur['umur14']+$data_umur['umur15']+$data_umur['umur16']+$data_umur['umur17'];?&gt;
&lt;/center&gt;
&lt;/th&gt;
&lt;?php
}
?&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;center&gt;VIII&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;0&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_lalu_laki_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_lalu_perempuan_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;&lt;?php echo $data['bulan_lalu_laki_viii']+$data['bulan_lalu_perempuan_viii'];?&gt;&lt;/center&gt;
&lt;/th&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['keluar_laki_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['keluar_perempuan_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['masuk_laki_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['masuk_perempuan_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_ini_laki_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_ini_perempuan_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;&lt;?php echo $data['bulan_ini_laki_viii']+$data['bulan_ini_perempuan_viii'];?&gt;&lt;/center&gt;
&lt;/th&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_islam_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_protestan_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_katolik_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_buddha_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_hindu_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_konghucu_viii'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;
&lt;?php echo $data1['agama_siswa_islam_viii']+$data1['agama_siswa_protestan_viii']+$data1['agama_siswa_katolik_viii']+$data1['agama_siswa_buddha_viii']+$data1['agama_siswa_hindu_viii']+$data1['agama_siswa_konghucu_viii'];?&gt;
&lt;/center&gt;
&lt;/th&gt;
&lt;?php
$sql_umur = mysql_query("SELECT
COUNT(IF(a.umur &lt;=11,1,NULL)) AS umur11,
COUNT(IF(a.umur=12,1,NULL)) AS umur12,
COUNT(IF(a.umur=13,1,NULL)) AS umur13,
COUNT(IF(a.umur=14,1,NULL)) AS umur14,
COUNT(IF(a.umur=15,1,NULL)) AS umur15,
COUNT(IF(a.umur=16,1,NULL)) AS umur16,
COUNT(IF(a.umur&gt;=17,1,NULL)) AS umur17
FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE())
AS umur FROM siswa
WHERE (rombel_siswa = 'VIII-A' OR rombel_siswa = 'VIII-B' OR rombel_siswa = 'VIII-C' OR rombel_siswa = 'VIII-D' OR rombel_siswa = 'VIII-E' OR rombel_siswa = 'VIII-F' OR rombel_siswa = 'VIII-G' OR rombel_siswa = 'VIII-H' OR rombel_siswa = 'VIII-I' OR rombel_siswa = 'VIII-J' OR rombel_siswa = 'VIII-K' OR rombel_siswa = 'VIII-L' OR rombel_siswa = 'VIII-M' OR rombel_siswa = 'VIII-N' OR rombel_siswa = 'VIII-O')
AND id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2') a");
while ($data_umur = mysql_fetch_assoc($sql_umur))
{
?&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur11'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur12'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur13'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur14'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur15'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur16'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur17'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;
&lt;?php echo $data_umur['umur11']+$data_umur['umur12']+$data_umur['umur13']+$data_umur['umur14']+$data_umur['umur15']+$data_umur['umur16']+$data_umur['umur17'];?&gt;
&lt;/center&gt;
&lt;/th&gt;
&lt;?php
}
?&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;center&gt;IX&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;0&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_lalu_laki_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_lalu_perempuan_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;&lt;?php echo $data['bulan_lalu_laki_ix']+$data['bulan_lalu_perempuan_ix'];?&gt;&lt;/center&gt;
&lt;/th&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['keluar_laki_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['keluar_perempuan_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['masuk_laki_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['masuk_perempuan_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_ini_laki_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data['bulan_ini_perempuan_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;&lt;?php echo $data['bulan_ini_laki_ix']+$data['bulan_ini_perempuan_ix'];?&gt;&lt;/center&gt;
&lt;/th&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_islam_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_protestan_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_katolik_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_buddha_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_hindu_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data1['agama_siswa_konghucu_ix'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;
&lt;?php echo $data1['agama_siswa_islam_ix']+$data1['agama_siswa_protestan_ix']+$data1['agama_siswa_katolik_ix']+$data1['agama_siswa_buddha_ix']+$data1['agama_siswa_hindu_ix']+$data1['agama_siswa_konghucu_ix'];?&gt;
&lt;/center&gt;
&lt;/th&gt;
&lt;?php
$sql_umur = mysql_query("SELECT
COUNT(IF(a.umur &lt;=11,1,NULL)) AS umur11,
COUNT(IF(a.umur=12,1,NULL)) AS umur12,
COUNT(IF(a.umur=13,1,NULL)) AS umur13,
COUNT(IF(a.umur=14,1,NULL)) AS umur14,
COUNT(IF(a.umur=15,1,NULL)) AS umur15,
COUNT(IF(a.umur=16,1,NULL)) AS umur16,
COUNT(IF(a.umur&gt;=17,1,NULL)) AS umur17
FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE())
AS umur
FROM siswa
WHERE (rombel_siswa = 'IX-A' OR rombel_siswa = 'IX-B' OR rombel_siswa = 'IX-C' OR rombel_siswa = 'IX-D' OR rombel_siswa = 'IX-E' OR rombel_siswa = 'IX-F' OR rombel_siswa = 'IX-G' OR rombel_siswa = 'IX-H' OR rombel_siswa = 'IX-I' OR rombel_siswa = 'IX-J' OR rombel_siswa = 'IX-K' OR rombel_siswa = 'IX-L' OR rombel_siswa = 'IX-M' OR rombel_siswa = 'IX-N' OR rombel_siswa = 'IX-O')
AND id_sekolah = '$_POST[nm_sekolah]' AND tanggal_data BETWEEN '$tgl1' AND '$tgl2') a");
while ($data_umur = mysql_fetch_assoc($sql_umur))
{
?&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur11'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur12'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur13'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur14'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur15'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur16'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;center&gt;&lt;?php echo $data_umur['umur17'];?&gt;&lt;/center&gt;
&lt;/td&gt;
&lt;th&gt;
&lt;center&gt;
&lt;?php echo $data_umur['umur11']+$data_umur['umur12']+$data_umur['umur13']+$data_umur['umur14']+$data_umur['umur15']+$data_umur['umur16']+$data_umur['umur17'];?&gt;
&lt;/center&gt;
&lt;/th&gt;
&lt;?php
}
?&gt;
&lt;/tr&gt;
&lt;/tr&gt;
&lt;?php
}
}
}
?&gt;
</tbody></pre><div><br>Kalau ga jelas, langsung tanya aja</div>