Read 172 times | Created 2013-05-30 07:55:15 | Updated 2013-05-30 07:55:15 | | |

 

<?php
/*
-- use test;

DROP TABLE IF EXISTS `jadwal_dokter`;
CREATE TABLE IF NOT EXISTS `jadwal_dokter` (
  `id_jd` tinyint(3) UNSIGNED NOT NULL AUTO_INCREMENT,
  `hari` varchar(30) NOT NULL,
  `id_dokter` tinyint(3) NOT NULL,
  `waktu` varchar(5) NOT NULL,
  PRIMARY KEY (`id_jd`)
) ENGINE=MyISAM;

INSERT INTO `jadwal_dokter`(`id_jd`,`hari`,`id_dokter`,`waktu`)
VALUES
(NULL,'SENIN',1,'PAGI'),
(NULL,'RABU',2,'SORE'),
(NULL,'SELASA',4,'PAGI'),
(NULL,'KAMIS',2,'PAGI'),
(NULL,'KAMIS',3,'PAGI'),
(NULL,'SENIN',2,'SORE'),
(NULL,'JUMAT',1,'PAGI'),
(NULL,'MINGGU',1,'PAGI'),
(NULL,'SABTU',3,'SORE'),
(NULL,'SENIN',3,'PAGI');

DROP TABLE IF EXISTS `dokter`;
CREATE TABLE IF NOT EXISTS `dokter` (
  `id_dokter` tinyint(3) UNSIGNED NOT NULL AUTO_INCREMENT,
  `kd_dokter` varchar(3) NOT NULL,
  `nm_dokter` varchar(30) NOT NULL,
  PRIMARY KEY (`id_dokter`)
) ENGINE=MyISAM;

INSERT INTO `dokter`(`id_dokter`,`kd_dokter`,`nm_dokter`)
VALUES
(NULL,'AA','Aulia Andri'),
(NULL,'JH','Joni Hartadi'),
(NULL,'DR','Dudi Rahmadi'),
(NULL,'VS','Vita Sari');


*/
//=== DATABASE CONNECTION===
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$dbname='test';
$db = new mysqli($dbhost,$dbuser,$dbpass,$dbname); 
?>
<!DOCTYPE html>
<html>
<head>
<title>Jadwal Dokter</title>
</head>
<body>
 <h2>Data Jadwal Dokter</h2>
 <table border='1'>
  <tr>
    <th>Jadwal</th>
    <th>Senin</th>
    <th>Selasa</th>
    <th>Rabu</th>
    <th>Kamis</th>
    <th>Jumat</th>
    <th>Sabtu</th>
    <th>Minggu</th>
  </tr>
<?php
  $sql="
   SELECT a.waktu,
   GROUP_CONCAT(a.senin SEPARATOR '<br/>') AS senin,
   GROUP_CONCAT(a.selasa SEPARATOR '<br/>') AS selasa,
   GROUP_CONCAT(a.rabu SEPARATOR '<br/>') AS rabu,
   GROUP_CONCAT(a.kamis SEPARATOR '<br/>') AS kamis,
   GROUP_CONCAT(a.jumat SEPARATOR '<br/>') AS jumat,
   GROUP_CONCAT(a.sabtu SEPARATOR '<br/>') AS sabtu,
   GROUP_CONCAT(a.minggu SEPARATOR '<br/>') AS minggu
   FROM
   (
   SELECT
     j.waktu,
     IF(j.hari='SENIN',d.nm_dokter,NULL) AS senin,
     IF(j.hari='SELASA',d.nm_dokter,NULL) AS selasa,
     IF(j.hari='RABU',d.nm_dokter,NULL) AS rabu,
     IF(j.hari='KAMIS',d.nm_dokter,NULL) AS kamis,
     IF(j.hari='JUMAT',d.nm_dokter,NULL) AS jumat,
     IF(j.hari='SABTU',d.nm_dokter,NULL) AS sabtu,
     IF(j.hari='MINGGU',d.nm_dokter,NULL) AS minggu
   FROM jadwal_dokter j
   JOIN dokter d USING(id_dokter)
   )a
   GROUP BY a.waktu   
   ";
if($result=$db->query($sql)){
  while($row=$result->fetch_object()){
    echo "
    <tr>
      <td>".$row->waktu."</td>
      <td>".(!empty($row->senin)?$row->senin:'&nbsp;')."</td>
      <td>".(!empty($row->selasa)?$row->selasa:'&nbsp;')."</td>
      <td>".(!empty($row->rabu)?$row->rabu:'&nbsp;')."</td>
      <td>".(!empty($row->kamis)?$row->kamis:'&nbsp;')."</td>
      <td>".(!empty($row->jumat)?$row->jumat:'&nbsp;')."</td>
      <td>".(!empty($row->sabtu)?$row->sabtu:'&nbsp;')."</td>
      <td>".(!empty($row->minggu)?$row->minggu:'&nbsp;')."</td>
    </tr>";
  }
}
?>
</table>
</body>
</html>