Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- -- use test;
- DROP TABLE IF EXISTS `tb_kelas`;
- CREATE TABLE IF NOT EXISTS `tb_kelas` (
- `id_kelas` tinyint(3) UNSIGNED NOT NULL AUTO_INCREMENT,
- `kelas` varchar(30) NOT NULL,
- PRIMARY KEY (`id_kelas`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
- INSERT INTO `tb_kelas`(`id_kelas`,`kelas`) VALUES(1,"Kelas 1"),(2,"Kelas 2"),(3,"Kelas 3");
- DROP TABLE IF EXISTS `tb_siswa`;
- CREATE TABLE IF NOT EXISTS `tb_siswa` (
- `id_siswa` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
- `id_kelas` tinyint(3) UNSIGNED NOT NULL,
- `nama` varchar(30) NOT NULL,
- PRIMARY KEY (`id_siswa`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
- INSERT INTO `tb_siswa`(`id_siswa`,`id_kelas`,`nama`) VALUES(1,1,"Shinta"),(2,2,"Budi"),(3,3,"Angel");
- DROP TABLE IF EXISTS `tb_jadwal`;
- CREATE TABLE IF NOT EXISTS `tb_jadwal` (
- `id_jadwal` tinyint(3) UNSIGNED NOT NULL AUTO_INCREMENT,
- `id_kelas` tinyint(3) UNSIGNED NOT NULL,
- `tgl` date NOT NULL,
- `pelajaran` varchar(30) NOT NULL,
- PRIMARY KEY (`id_jadwal`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
- INSERT INTO `tb_jadwal`(`id_jadwal`,`id_kelas`,`tgl`,`pelajaran`) VALUES(1,1,"2012-09-02","Matematika"),(2,1,"2012-09-02","Bahasa Indonesia"),(3,1,"2012-09-02","Biologi"),(4,2,"2012-09-02","IPS"),(5,2,"2012-09-02","IPA"),(6,2,"2012-09-02","Matematika"),(7,3,"2012-09-02","Fisika"),(8,3,"2012-09-02","Kimia");
- */
- $db = new mysqli("localhost", "root", "", "test");
- $sql="SELECT JADWAL.tgl, SISWA.nama, KELAS.kelas, JADWAL.pelajaran,
- ( SELECT COUNT(id_jadwal)
- FROM tb_jadwal
- WHERE id_kelas=KELAS.id_kelas) AS jml
- FROM tb_siswa SISWA
- LEFT JOIN tb_kelas KELAS ON KELAS.id_kelas=SISWA.id_kelas
- LEFT JOIN tb_jadwal JADWAL ON JADWAL.id_kelas=KELAS.id_kelas
- ORDER BY JADWAL.tgl,KELAS.id_kelas,SISWA.id_siswa";
- $result=$db->query($sql);
- $no = 1;
- $jum = 1;
- echo '<table cellpadding="5 " border="1">';
- echo '<tr><th>No</th><th>Tgl</th><th>Kelas</th><th>Siswa</th><th>Pelajaran</th></tr>';
- while($row=$result->fetch_object()) {
- echo '<tr>';
- if($jum <= 1) {
- echo '<td align="center" rowspan="'.$row->jml.'">'.$no.'</td>';
- echo '<td rowspan="'.$row->jml.'">'.$row->tgl.'</td>';
- echo '<td rowspan="'.$row->jml.'">'.$row->nama.'</td>';
- echo '<td rowspan="'.$row->jml.'">'.$row->kelas.'</td>';
- $jum = $row->jml;
- $no++;
- } else {
- $jum = $jum - 1;
- }
- echo '<td>'.$row->pelajaran.'</td>';
- echo '</tr>';
- }
- echo '</table>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement