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?

avatar barkah03
@barkah03

33 Kontribusi 9 Poin

Diperbarui 2 tahun yang lalu

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>&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[&#039;tgl1&#039;]) &amp;amp;&amp;amp; isset($_POST[&#039;tgl2&#039;])){

$sql = mysql_query(&quot;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 &quot;. $where_nm_sekolah .&quot; a.id_sekolah = &#039;$_POST[nm_sekolah]&#039; AND tanggal_data BETWEEN &#039;$tgl1&#039; AND &#039;$tgl2&#039;

    ORDER BY id_kecamatan ASC&quot;);&lt;/pre&gt;&lt;div&gt;&lt;br&gt;Ini full nya :&lt;/div&gt;&lt;pre&gt;&amp;lt;tbody&amp;gt;

&amp;lt;?php                                
//untuk option
    $tgl1=$_POST[&#039;tgl1&#039;];
    $tgl2=$_POST[&#039;tgl2&#039;];
    $nm_sekolah=$_POST[&#039;nm_sekolah&#039;];
    $where_nm_sekolah = &quot;&quot;;
    if ($nm_sekolah != &quot;&quot;) {
        $where_nm_sekolah = &quot;a.id_sekolah = &#039;&quot;. $_POST[&#039;nm_sekolah&#039;] .&quot;&#039; AND&quot;;
    }

    
    
if (isset($_POST[&#039;tgl1&#039;]) &amp;amp;&amp;amp; isset($_POST[&#039;tgl2&#039;]))
{

$sql = mysql_query(&quot;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 &quot;. $where_nm_sekolah .&quot; a.id_sekolah = &#039;$_POST[nm_sekolah]&#039; AND tanggal_data BETWEEN &#039;$tgl1&#039; AND &#039;$tgl2&#039;

    ORDER BY id_kecamatan ASC&quot;);

while ($data = mysql_fetch_assoc($sql)) 

{

?&amp;gt;



&amp;lt;tr&amp;gt;

&amp;lt;tr&amp;gt;
    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;VII&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;0&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_lalu_laki_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_lalu_perempuan_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_lalu_laki_vii&#039;]+$data[&#039;bulan_lalu_perempuan_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;keluar_laki_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;keluar_perempuan_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;masuk_laki_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;masuk_perempuan_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_ini_laki_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_ini_perempuan_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_ini_laki_vii&#039;]+$data[&#039;bulan_ini_perempuan_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;



    &amp;lt;?php

        

        

        $sql1 = mysql_query(&quot;SELECT a.*, b.nm_kecamatan AS nm_kecamatan, c.nm_sekolah AS nm_sekolah, 

                        IFNULL(sum(a.agama_siswa=&#039;Islam&#039; AND (rombel_siswa = &#039;VII-A&#039; OR rombel_siswa = &#039;VII-B&#039; OR rombel_siswa = &#039;VII-C&#039; OR rombel_siswa = &#039;VII-D&#039; OR rombel_siswa = &#039;VII-E&#039; OR rombel_siswa = &#039;VII-F&#039; OR rombel_siswa = &#039;VII-G&#039; OR rombel_siswa = &#039;VII-H&#039; OR rombel_siswa = &#039;VII-I&#039; OR rombel_siswa = &#039;VII-J&#039; OR rombel_siswa = &#039;VII-K&#039; OR rombel_siswa = &#039;VII-L&#039; OR rombel_siswa = &#039;VII-M&#039; OR rombel_siswa = &#039;VII-N&#039; OR rombel_siswa = &#039;VII-O&#039;)),0) AS agama_siswa_islam_vii, IFNULL(sum(a.agama_siswa=&#039;Protestan&#039; AND (rombel_siswa = &#039;VII-A&#039; OR rombel_siswa = &#039;VII-B&#039; OR rombel_siswa = &#039;VII-C&#039; OR rombel_siswa = &#039;VII-D&#039; OR rombel_siswa = &#039;VII-E&#039; OR rombel_siswa = &#039;VII-F&#039; OR rombel_siswa = &#039;VII-G&#039; OR rombel_siswa = &#039;VII-H&#039; OR rombel_siswa = &#039;VII-I&#039; OR rombel_siswa = &#039;VII-J&#039; OR rombel_siswa = &#039;VII-K&#039; OR rombel_siswa = &#039;VII-L&#039; OR rombel_siswa = &#039;VII-M&#039; OR rombel_siswa = &#039;VII-N&#039; OR rombel_siswa = &#039;VII-O&#039;)),0) AS agama_siswa_protestan_vii, IFNULL(sum(a.agama_siswa=&#039;Katolik&#039; AND (rombel_siswa = &#039;VII-A&#039; OR rombel_siswa = &#039;VII-B&#039; OR rombel_siswa = &#039;VII-C&#039; OR rombel_siswa = &#039;VII-D&#039; OR rombel_siswa = &#039;VII-E&#039; OR rombel_siswa = &#039;VII-F&#039; OR rombel_siswa = &#039;VII-G&#039; OR rombel_siswa = &#039;VII-H&#039; OR rombel_siswa = &#039;VII-I&#039; OR rombel_siswa = &#039;VII-J&#039; OR rombel_siswa = &#039;VII-K&#039; OR rombel_siswa = &#039;VII-L&#039; OR rombel_siswa = &#039;VII-M&#039; OR rombel_siswa = &#039;VII-N&#039; OR rombel_siswa = &#039;VII-O&#039;)),0) AS agama_siswa_katolik_vii, IFNULL(sum(a.agama_siswa=&#039;Buddha&#039; AND (rombel_siswa = &#039;VII-A&#039; OR rombel_siswa = &#039;VII-B&#039; OR rombel_siswa = &#039;VII-C&#039; OR rombel_siswa = &#039;VII-D&#039; OR rombel_siswa = &#039;VII-E&#039; OR rombel_siswa = &#039;VII-F&#039; OR rombel_siswa = &#039;VII-G&#039; OR rombel_siswa = &#039;VII-H&#039; OR rombel_siswa = &#039;VII-I&#039; OR rombel_siswa = &#039;VII-J&#039; OR rombel_siswa = &#039;VII-K&#039; OR rombel_siswa = &#039;VII-L&#039; OR rombel_siswa = &#039;VII-M&#039; OR rombel_siswa = &#039;VII-N&#039; OR rombel_siswa = &#039;VII-O&#039;)),0) AS agama_siswa_buddha_vii, IFNULL(sum(a.agama_siswa=&#039;Hindu&#039; AND (rombel_siswa = &#039;VII-A&#039; OR rombel_siswa = &#039;VII-B&#039; OR rombel_siswa = &#039;VII-C&#039; OR rombel_siswa = &#039;VII-D&#039; OR rombel_siswa = &#039;VII-E&#039; OR rombel_siswa = &#039;VII-F&#039; OR rombel_siswa = &#039;VII-G&#039; OR rombel_siswa = &#039;VII-H&#039; OR rombel_siswa = &#039;VII-I&#039; OR rombel_siswa = &#039;VII-J&#039; OR rombel_siswa = &#039;VII-K&#039; OR rombel_siswa = &#039;VII-L&#039; OR rombel_siswa = &#039;VII-M&#039; OR rombel_siswa = &#039;VII-N&#039; OR rombel_siswa = &#039;VII-O&#039;)),0) AS agama_siswa_hindu_vii, IFNULL(sum(a.agama_siswa=&#039;Konghucu&#039; AND (rombel_siswa = &#039;VII-A&#039; OR rombel_siswa = &#039;VII-B&#039; OR rombel_siswa = &#039;VII-C&#039; OR rombel_siswa = &#039;VII-D&#039; OR rombel_siswa = &#039;VII-E&#039; OR rombel_siswa = &#039;VII-F&#039; OR rombel_siswa = &#039;VII-G&#039; OR rombel_siswa = &#039;VII-H&#039; OR rombel_siswa = &#039;VII-I&#039; OR rombel_siswa = &#039;VII-J&#039; OR rombel_siswa = &#039;VII-K&#039; OR rombel_siswa = &#039;VII-L&#039; OR rombel_siswa = &#039;VII-M&#039; OR rombel_siswa = &#039;VII-N&#039; OR rombel_siswa = &#039;VII-O&#039;)),0) AS agama_siswa_konghucu_vii,

                        IFNULL(sum(a.agama_siswa=&#039;Islam&#039; AND (rombel_siswa = &#039;VIII-A&#039; OR rombel_siswa = &#039;VIII-B&#039; OR rombel_siswa = &#039;VIII-C&#039; OR rombel_siswa = &#039;VIII-D&#039; OR rombel_siswa = &#039;VIII-E&#039; OR rombel_siswa = &#039;VIII-F&#039; OR rombel_siswa = &#039;VIII-G&#039; OR rombel_siswa = &#039;VIII-H&#039; OR rombel_siswa = &#039;VIII-I&#039; OR rombel_siswa = &#039;VIII-J&#039; OR rombel_siswa = &#039;VIII-K&#039; OR rombel_siswa = &#039;VIII-L&#039; OR rombel_siswa = &#039;VIII-M&#039; OR rombel_siswa = &#039;VIII-N&#039; OR rombel_siswa = &#039;VIII-O&#039;)),0) AS agama_siswa_islam_viii, IFNULL(sum(a.agama_siswa=&#039;Protestan&#039; AND (rombel_siswa = &#039;VIII-A&#039; OR rombel_siswa = &#039;VIII-B&#039; OR rombel_siswa = &#039;VIII-C&#039; OR rombel_siswa = &#039;VIII-D&#039; OR rombel_siswa = &#039;VIII-E&#039; OR rombel_siswa = &#039;VIII-F&#039; OR rombel_siswa = &#039;VIII-G&#039; OR rombel_siswa = &#039;VIII-H&#039; OR rombel_siswa = &#039;VIII-I&#039; OR rombel_siswa = &#039;VIII-J&#039; OR rombel_siswa = &#039;VIII-K&#039; OR rombel_siswa = &#039;VIII-L&#039; OR rombel_siswa = &#039;VIII-M&#039; OR rombel_siswa = &#039;VIII-N&#039; OR rombel_siswa = &#039;VIII-O&#039;)),0) AS agama_siswa_protestan_viii, IFNULL(sum(a.agama_siswa=&#039;Katolik&#039; AND (rombel_siswa = &#039;VIII-A&#039; OR rombel_siswa = &#039;VIII-B&#039; OR rombel_siswa = &#039;VIII-C&#039; OR rombel_siswa = &#039;VIII-D&#039; OR rombel_siswa = &#039;VIII-E&#039; OR rombel_siswa = &#039;VIII-F&#039; OR rombel_siswa = &#039;VIII-G&#039; OR rombel_siswa = &#039;VIII-H&#039; OR rombel_siswa = &#039;VIII-I&#039; OR rombel_siswa = &#039;VIII-J&#039; OR rombel_siswa = &#039;VIII-K&#039; OR rombel_siswa = &#039;VIII-L&#039; OR rombel_siswa = &#039;VIII-M&#039; OR rombel_siswa = &#039;VIII-N&#039; OR rombel_siswa = &#039;VIII-O&#039;)),0) AS agama_siswa_katolik_viii, IFNULL(sum(a.agama_siswa=&#039;Buddha&#039; AND (rombel_siswa = &#039;VIII-A&#039; OR rombel_siswa = &#039;VIII-B&#039; OR rombel_siswa = &#039;VIII-C&#039; OR rombel_siswa = &#039;VIII-D&#039; OR rombel_siswa = &#039;VIII-E&#039; OR rombel_siswa = &#039;VIII-F&#039; OR rombel_siswa = &#039;VIII-G&#039; OR rombel_siswa = &#039;VIII-H&#039; OR rombel_siswa = &#039;VIII-I&#039; OR rombel_siswa = &#039;VIII-J&#039; OR rombel_siswa = &#039;VIII-K&#039; OR rombel_siswa = &#039;VIII-L&#039; OR rombel_siswa = &#039;VIII-M&#039; OR rombel_siswa = &#039;VIII-N&#039; OR rombel_siswa = &#039;VIII-O&#039;)),0) AS agama_siswa_buddha_viii, IFNULL(sum(a.agama_siswa=&#039;Hindu&#039; AND (rombel_siswa = &#039;VIII-A&#039; OR rombel_siswa = &#039;VIII-B&#039; OR rombel_siswa = &#039;VIII-C&#039; OR rombel_siswa = &#039;VIII-D&#039; OR rombel_siswa = &#039;VIII-E&#039; OR rombel_siswa = &#039;VIII-F&#039; OR rombel_siswa = &#039;VIII-G&#039; OR rombel_siswa = &#039;VIII-H&#039; OR rombel_siswa = &#039;VIII-I&#039; OR rombel_siswa = &#039;VIII-J&#039; OR rombel_siswa = &#039;VIII-K&#039; OR rombel_siswa = &#039;VIII-L&#039; OR rombel_siswa = &#039;VIII-M&#039; OR rombel_siswa = &#039;VIII-N&#039; OR rombel_siswa = &#039;VIII-O&#039;)),0) AS agama_siswa_hindu_viii, IFNULL(sum(a.agama_siswa=&#039;Konghucu&#039; AND (rombel_siswa = &#039;VIII-A&#039; OR rombel_siswa = &#039;VIII-B&#039; OR rombel_siswa = &#039;VIII-C&#039; OR rombel_siswa = &#039;VIII-D&#039; OR rombel_siswa = &#039;VIII-E&#039; OR rombel_siswa = &#039;VIII-F&#039; OR rombel_siswa = &#039;VIII-G&#039; OR rombel_siswa = &#039;VIII-H&#039; OR rombel_siswa = &#039;VIII-I&#039; OR rombel_siswa = &#039;VIII-J&#039; OR rombel_siswa = &#039;VIII-K&#039; OR rombel_siswa = &#039;VIII-L&#039; OR rombel_siswa = &#039;VIII-M&#039; OR rombel_siswa = &#039;VIII-N&#039; OR rombel_siswa = &#039;VIII-O&#039;)),0) AS agama_siswa_konghucu_viii,

                        IFNULL(sum(a.agama_siswa=&#039;Islam&#039; AND (rombel_siswa = &#039;IX-A&#039; OR rombel_siswa = &#039;IX-B&#039; OR rombel_siswa = &#039;IX-C&#039; OR rombel_siswa = &#039;IX-D&#039; OR rombel_siswa = &#039;IX-E&#039; OR rombel_siswa = &#039;IX-F&#039; OR rombel_siswa = &#039;IX-G&#039; OR rombel_siswa = &#039;IX-H&#039; OR rombel_siswa = &#039;IX-I&#039; OR rombel_siswa = &#039;IX-J&#039; OR rombel_siswa = &#039;IX-K&#039; OR rombel_siswa = &#039;IX-L&#039; OR rombel_siswa = &#039;IX-M&#039; OR rombel_siswa = &#039;IX-N&#039; OR rombel_siswa = &#039;IX-O&#039;)),0) AS agama_siswa_islam_ix, IFNULL(sum(a.agama_siswa=&#039;Protestan&#039; AND (rombel_siswa = &#039;IX-A&#039; OR rombel_siswa = &#039;IX-B&#039; OR rombel_siswa = &#039;IX-C&#039; OR rombel_siswa = &#039;IX-D&#039; OR rombel_siswa = &#039;IX-E&#039; OR rombel_siswa = &#039;IX-F&#039; OR rombel_siswa = &#039;IX-G&#039; OR rombel_siswa = &#039;IX-H&#039; OR rombel_siswa = &#039;IX-I&#039; OR rombel_siswa = &#039;IX-J&#039; OR rombel_siswa = &#039;IX-K&#039; OR rombel_siswa = &#039;IX-L&#039; OR rombel_siswa = &#039;IX-M&#039; OR rombel_siswa = &#039;IX-N&#039; OR rombel_siswa = &#039;IX-O&#039;)),0) AS agama_siswa_protestan_ix, IFNULL(sum(a.agama_siswa=&#039;Katolik&#039; AND (rombel_siswa = &#039;IX-A&#039; OR rombel_siswa = &#039;IX-B&#039; OR rombel_siswa = &#039;IX-C&#039; OR rombel_siswa = &#039;IX-D&#039; OR rombel_siswa = &#039;IX-E&#039; OR rombel_siswa = &#039;IX-F&#039; OR rombel_siswa = &#039;IX-G&#039; OR rombel_siswa = &#039;IX-H&#039; OR rombel_siswa = &#039;IX-I&#039; OR rombel_siswa = &#039;IX-J&#039; OR rombel_siswa = &#039;IX-K&#039; OR rombel_siswa = &#039;IX-L&#039; OR rombel_siswa = &#039;IX-M&#039; OR rombel_siswa = &#039;IX-N&#039; OR rombel_siswa = &#039;IX-O&#039;)),0) AS agama_siswa_katolik_ix, IFNULL(sum(a.agama_siswa=&#039;Buddha&#039; AND (rombel_siswa = &#039;IX-A&#039; OR rombel_siswa = &#039;IX-B&#039; OR rombel_siswa = &#039;IX-C&#039; OR rombel_siswa = &#039;IX-D&#039; OR rombel_siswa = &#039;IX-E&#039; OR rombel_siswa = &#039;IX-F&#039; OR rombel_siswa = &#039;IX-G&#039; OR rombel_siswa = &#039;IX-H&#039; OR rombel_siswa = &#039;IX-I&#039; OR rombel_siswa = &#039;IX-J&#039; OR rombel_siswa = &#039;IX-K&#039; OR rombel_siswa = &#039;IX-L&#039; OR rombel_siswa = &#039;IX-M&#039; OR rombel_siswa = &#039;IX-N&#039; OR rombel_siswa = &#039;IX-O&#039;)),0) AS agama_siswa_buddha_ix, IFNULL(sum(a.agama_siswa=&#039;Hindu&#039; AND (rombel_siswa = &#039;IX-A&#039; OR rombel_siswa = &#039;IX-B&#039; OR rombel_siswa = &#039;IX-C&#039; OR rombel_siswa = &#039;IX-D&#039; OR rombel_siswa = &#039;IX-E&#039; OR rombel_siswa = &#039;IX-F&#039; OR rombel_siswa = &#039;IX-G&#039; OR rombel_siswa = &#039;IX-H&#039; OR rombel_siswa = &#039;IX-I&#039; OR rombel_siswa = &#039;IX-J&#039; OR rombel_siswa = &#039;IX-K&#039; OR rombel_siswa = &#039;IX-L&#039; OR rombel_siswa = &#039;IX-M&#039; OR rombel_siswa = &#039;IX-N&#039; OR rombel_siswa = &#039;IX-O&#039;)),0) AS agama_siswa_hindu_ix, IFNULL(sum(a.agama_siswa=&#039;Konghucu&#039; AND (rombel_siswa = &#039;IX-A&#039; OR rombel_siswa = &#039;IX-B&#039; OR rombel_siswa = &#039;IX-C&#039; OR rombel_siswa = &#039;IX-D&#039; OR rombel_siswa = &#039;IX-E&#039; OR rombel_siswa = &#039;IX-F&#039; OR rombel_siswa = &#039;IX-G&#039; OR rombel_siswa = &#039;IX-H&#039; OR rombel_siswa = &#039;IX-I&#039; OR rombel_siswa = &#039;IX-J&#039; OR rombel_siswa = &#039;IX-K&#039; OR rombel_siswa = &#039;IX-L&#039; OR rombel_siswa = &#039;IX-M&#039; OR rombel_siswa = &#039;IX-N&#039; OR rombel_siswa = &#039;IX-O&#039;)),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 = &#039;$_POST[nm_sekolah]&#039; AND tanggal_data BETWEEN &#039;$tgl1&#039; AND &#039;$tgl2&#039;&quot;);

                while ($data1 = mysql_fetch_assoc($sql1)) 

        {

        ?&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_islam_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_protestan_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_katolik_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_buddha_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_hindu_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_konghucu_vii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;
            &amp;lt;?php echo $data1[&#039;agama_siswa_islam_vii&#039;]+$data1[&#039;agama_siswa_protestan_vii&#039;]+$data1[&#039;agama_siswa_katolik_vii&#039;]+$data1[&#039;agama_siswa_buddha_vii&#039;]+$data1[&#039;agama_siswa_hindu_vii&#039;]+$data1[&#039;agama_siswa_konghucu_vii&#039;];?&amp;gt;
        &amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;



    &amp;lt;?php

        $sql_umur = mysql_query(&quot;SELECT 

                    COUNT(IF(a.umur &amp;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&amp;gt;=17,1,NULL)) AS umur17 

                    FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE()) 

                    AS umur 

                    FROM siswa 

                    WHERE (rombel_siswa = &#039;VII-A&#039; OR rombel_siswa = &#039;VII-B&#039; OR rombel_siswa = &#039;VII-C&#039; OR rombel_siswa = &#039;VII-D&#039; OR rombel_siswa = &#039;VII-E&#039; OR rombel_siswa = &#039;VII-F&#039; OR rombel_siswa = &#039;VII-G&#039; OR rombel_siswa = &#039;VII-H&#039; OR rombel_siswa = &#039;VII-I&#039; OR rombel_siswa = &#039;VII-J&#039; OR rombel_siswa = &#039;VII-K&#039; OR rombel_siswa = &#039;VII-L&#039; OR rombel_siswa = &#039;VII-M&#039; OR rombel_siswa = &#039;VII-N&#039; OR rombel_siswa = &#039;VII-O&#039;) 

                    AND id_sekolah = &#039;$_POST[nm_sekolah]&#039; AND tanggal_data BETWEEN &#039;$tgl1&#039; AND &#039;$tgl2&#039;) a&quot;);

        while ($data_umur = mysql_fetch_assoc($sql_umur)) 

        {

        ?&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur11&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur12&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur13&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur14&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur15&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur16&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur17&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;
            &amp;lt;?php echo $data_umur[&#039;umur11&#039;]+$data_umur[&#039;umur12&#039;]+$data_umur[&#039;umur13&#039;]+$data_umur[&#039;umur14&#039;]+$data_umur[&#039;umur15&#039;]+$data_umur[&#039;umur16&#039;]+$data_umur[&#039;umur17&#039;];?&amp;gt;
        &amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;

    &amp;lt;?php

            }

        ?&amp;gt;





&amp;lt;/tr&amp;gt;



&amp;lt;tr&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;VIII&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;0&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_lalu_laki_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_lalu_perempuan_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_lalu_laki_viii&#039;]+$data[&#039;bulan_lalu_perempuan_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;keluar_laki_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;keluar_perempuan_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;masuk_laki_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;masuk_perempuan_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_ini_laki_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_ini_perempuan_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_ini_laki_viii&#039;]+$data[&#039;bulan_ini_perempuan_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_islam_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_protestan_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_katolik_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_buddha_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_hindu_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_konghucu_viii&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;
            &amp;lt;?php echo $data1[&#039;agama_siswa_islam_viii&#039;]+$data1[&#039;agama_siswa_protestan_viii&#039;]+$data1[&#039;agama_siswa_katolik_viii&#039;]+$data1[&#039;agama_siswa_buddha_viii&#039;]+$data1[&#039;agama_siswa_hindu_viii&#039;]+$data1[&#039;agama_siswa_konghucu_viii&#039;];?&amp;gt;
        &amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;



    &amp;lt;?php

            $sql_umur = mysql_query(&quot;SELECT 

                        COUNT(IF(a.umur &amp;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&amp;gt;=17,1,NULL)) AS umur17 

                        FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE()) 

                        AS umur FROM siswa 

                        WHERE (rombel_siswa = &#039;VIII-A&#039; OR rombel_siswa = &#039;VIII-B&#039; OR rombel_siswa = &#039;VIII-C&#039; OR rombel_siswa = &#039;VIII-D&#039; OR rombel_siswa = &#039;VIII-E&#039; OR rombel_siswa = &#039;VIII-F&#039; OR rombel_siswa = &#039;VIII-G&#039; OR rombel_siswa = &#039;VIII-H&#039; OR rombel_siswa = &#039;VIII-I&#039; OR rombel_siswa = &#039;VIII-J&#039; OR rombel_siswa = &#039;VIII-K&#039; OR rombel_siswa = &#039;VIII-L&#039; OR rombel_siswa = &#039;VIII-M&#039; OR rombel_siswa = &#039;VIII-N&#039; OR rombel_siswa = &#039;VIII-O&#039;) 

                        AND id_sekolah = &#039;$_POST[nm_sekolah]&#039; AND tanggal_data BETWEEN &#039;$tgl1&#039; AND &#039;$tgl2&#039;) a&quot;);

            while ($data_umur = mysql_fetch_assoc($sql_umur)) 

            {

            ?&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur11&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur12&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur13&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur14&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur15&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur16&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur17&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;
            &amp;lt;?php echo $data_umur[&#039;umur11&#039;]+$data_umur[&#039;umur12&#039;]+$data_umur[&#039;umur13&#039;]+$data_umur[&#039;umur14&#039;]+$data_umur[&#039;umur15&#039;]+$data_umur[&#039;umur16&#039;]+$data_umur[&#039;umur17&#039;];?&amp;gt;
        &amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;

    &amp;lt;?php

        }

        ?&amp;gt;

&amp;lt;/tr&amp;gt;



&amp;lt;tr&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;IX&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;0&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_lalu_laki_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_lalu_perempuan_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_lalu_laki_ix&#039;]+$data[&#039;bulan_lalu_perempuan_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;keluar_laki_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;keluar_perempuan_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;masuk_laki_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;masuk_perempuan_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_ini_laki_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_ini_perempuan_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data[&#039;bulan_ini_laki_ix&#039;]+$data[&#039;bulan_ini_perempuan_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_islam_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_protestan_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_katolik_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_buddha_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_hindu_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data1[&#039;agama_siswa_konghucu_ix&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;
            &amp;lt;?php echo $data1[&#039;agama_siswa_islam_ix&#039;]+$data1[&#039;agama_siswa_protestan_ix&#039;]+$data1[&#039;agama_siswa_katolik_ix&#039;]+$data1[&#039;agama_siswa_buddha_ix&#039;]+$data1[&#039;agama_siswa_hindu_ix&#039;]+$data1[&#039;agama_siswa_konghucu_ix&#039;];?&amp;gt;
        &amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;



    &amp;lt;?php

        $sql_umur = mysql_query(&quot;SELECT 

                    COUNT(IF(a.umur &amp;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&amp;gt;=17,1,NULL)) AS umur17 

                    FROM (SELECT TIMESTAMPDIFF(YEAR, tanggal_lahir, CURDATE()) 

                    AS umur 

                    FROM siswa 

                    WHERE (rombel_siswa = &#039;IX-A&#039; OR rombel_siswa = &#039;IX-B&#039; OR rombel_siswa = &#039;IX-C&#039; OR rombel_siswa = &#039;IX-D&#039; OR rombel_siswa = &#039;IX-E&#039; OR rombel_siswa = &#039;IX-F&#039; OR rombel_siswa = &#039;IX-G&#039; OR rombel_siswa = &#039;IX-H&#039; OR rombel_siswa = &#039;IX-I&#039; OR rombel_siswa = &#039;IX-J&#039; OR rombel_siswa = &#039;IX-K&#039; OR rombel_siswa = &#039;IX-L&#039; OR rombel_siswa = &#039;IX-M&#039; OR rombel_siswa = &#039;IX-N&#039; OR rombel_siswa = &#039;IX-O&#039;) 

                    AND id_sekolah = &#039;$_POST[nm_sekolah]&#039; AND tanggal_data BETWEEN &#039;$tgl1&#039; AND &#039;$tgl2&#039;) a&quot;);

        while ($data_umur = mysql_fetch_assoc($sql_umur)) 

        {

        ?&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur11&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur12&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur13&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;



    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur14&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur15&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur16&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;td&amp;gt;
        &amp;lt;center&amp;gt;&amp;lt;?php echo $data_umur[&#039;umur17&#039;];?&amp;gt;&amp;lt;/center&amp;gt;
    &amp;lt;/td&amp;gt;

    &amp;lt;th&amp;gt;
        &amp;lt;center&amp;gt;
            &amp;lt;?php echo $data_umur[&#039;umur11&#039;]+$data_umur[&#039;umur12&#039;]+$data_umur[&#039;umur13&#039;]+$data_umur[&#039;umur14&#039;]+$data_umur[&#039;umur15&#039;]+$data_umur[&#039;umur16&#039;]+$data_umur[&#039;umur17&#039;];?&amp;gt;
        &amp;lt;/center&amp;gt;
    &amp;lt;/th&amp;gt;

    &amp;lt;?php

            }

        ?&amp;gt;

&amp;lt;/tr&amp;gt;

&amp;lt;/tr&amp;gt;



&amp;lt;?php

        }

    }
}

?&amp;gt;

&lt;/tbody&gt;</pre><div><br>Kalau ga jelas, langsung tanya aja</div>

avatar Nandar
@Nandar

648 Kontribusi 204 Poin

Dipost 2 tahun yang lalu

Login untuk ikut Jawaban