Read 121 times | Created 2013-07-25 05:31:42 | Updated 2013-07-25 05:31:42 | | |

 

<?php
/******************************** 
/ DATA PEMINJAMAN BUKU v2
/ FILENAME     : rekap2.php 
/ CREATED BY   : CAHYA DSN 
/ CREATED DATE : 2013-07-25 
/*******************************
DROP TABLE IF EXISTS `tbl_nama`; 
CREATE TABLE IF NOT EXISTS `tbl_nama` ( 
  `id_nama` INT(11) unsigned NOT NULL AUTO_INCREMENT,
  `nama` VARCHAR(10)NOT NULL,
  PRIMARY KEY(`id_nama`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8; 
-- Dumping data for table `tbl_nama` 
INSERT INTO `tbl_nama`(`nama`)
VALUES
('odi'),('dio'),('ido');

DROP TABLE IF EXISTS `tbl_buku`; 
CREATE TABLE IF NOT EXISTS `tbl_buku` ( 
  `id_buku` INT(11) unsigned NOT NULL AUTO_INCREMENT,
  `buku` VARCHAR(10)NOT NULL,
  PRIMARY KEY(`id_buku`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8; 
-- Dumping data for table `tbl_buku` 
INSERT INTO `tbl_buku`(`buku`)
VALUES
('abc'),('def'),('xyz'),('hij');

DROP TABLE IF EXISTS `tbl_pinjam`; 
CREATE TABLE IF NOT EXISTS `tbl_pinjam` ( 
  `id_nama` INT(11) unsigned NOT NULL,
  `id_buku` INT(11) unsigned NOT NULL, 
  `tgl_kembali` DATE NOT NULL
) ENGINE=MyISAM  DEFAULT CHARSET=utf8; 
-- Dumping data for table `tbl_pinjam` 
INSERT INTO `tbl_pinjam`(`id_nama`,`id_buku`,`tgl_kembali`)
VALUES
(1,1,'2013-07-25'),
(1,2,'2013-07-26'),
(2,3,'2013-07-05'),
(3,4,'2013-07-27');
*/
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$dbname='test';
$db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
$sql="SELECT 
       n.nama, 
       GROUP_CONCAT(
          CONCAT('buku yang dipinjam ',b.buku,' pengembalian buku tgl ',p.tgl_kembali) 
          SEPARATOR ' dan '
         ) AS kembali 
    FROM 
      tbl_pinjam p 
      JOIN tbl_nama n USING(id_nama)
      JOIN tbl_buku b USING(id_buku)
    GROUP BY nama ";
if($result=$db->query($sql))
{
  while($row=$result->fetch_object())
  {
    echo $row->nama."=".$row->kembali."<br>n";
  }
}
?>