Postingan lainnya
Cara membuat scheduler di mysql dengan pemicunya tanggal
Saya mempunyai 4 buah tabel
CREATE DATABASE IF NOT EXISTS `b_hotel`;
USE `b_hotel`;
/*Table structure for table `booking` */
DROP TABLE IF EXISTS `booking`;
CREATE TABLE `booking` (
`booking_id` int(11) NOT NULL,
`customer_id` int(11) DEFAULT NULL,
`tgl_book` datetime DEFAULT NULL,
`checkin` date DEFAULT NULL,
`checkout` date DEFAULT NULL,
`no_kamar` int(11) DEFAULT NULL,
PRIMARY KEY (`booking_id`),
KEY `customer_id` (`customer_id`),
KEY `no_kamar` (`no_kamar`),
CONSTRAINT `booking_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`),
CONSTRAINT `booking_ibfk_2` FOREIGN KEY (`no_kamar`) REFERENCES `kamar` (`no_kamar`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Data for the table `booking` */
/*Table structure for table `customer` */
DROP TABLE IF EXISTS `customer`;
CREATE TABLE `customer` (
`customer_id` int(11) NOT NULL,
`nama_customer` varchar(50) DEFAULT NULL,
`no_telp` varchar(13) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
PRIMARY KEY (`customer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Data for the table `customer` */
insert into `customer`(`customer_id`,`nama_customer`,`no_telp`,`email`) values
(1,'ABC','123','email@email.com');
/*Table structure for table `kamar` */
DROP TABLE IF EXISTS `kamar`;
CREATE TABLE `kamar` (
`no_kamar` int(11) NOT NULL,
`no_tipe` smallint(6) DEFAULT NULL,
`status` enum('Kosong','Terpakai') DEFAULT NULL,
`img` varchar(50) DEFAULT NULL,
PRIMARY KEY (`no_kamar`),
KEY `no_tipe` (`no_tipe`),
CONSTRAINT `kamar_ibfk_1` FOREIGN KEY (`no_tipe`) REFERENCES `tipe_kamar` (`no_tipe`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Data for the table `kamar` */
insert into `kamar`(`no_kamar`,`no_tipe`,`status`,`img`) values
(101,1,'Kosong','assets/img/room/standard_1.jpg'),
(102,2,'Kosong','assets/img/room/standard_2.jpg'),
(301,3,'Kosong','assets/img/room/deluxe_1.jpg'),
(302,4,'Kosong','assets/img/room/deluxe_2.jpg'),
(601,5,'Kosong','assets/img/room/executive_1.jpg'),
(602,6,'Kosong','assets/img/room/executive_2.jpg');
/*Table structure for table `tipe_kamar` */
DROP TABLE IF EXISTS `tipe_kamar`;
CREATE TABLE `tipe_kamar` (
`no_tipe` smallint(6) NOT NULL AUTO_INCREMENT,
`nama_tipe` varchar(30) DEFAULT NULL,
`harga` int(7) DEFAULT NULL,
`dewasa` smallint(1) DEFAULT NULL,
PRIMARY KEY (`no_tipe`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;
/*Data for the table `tipe_kamar` */
insert into `tipe_kamar`(`no_tipe`,`nama_tipe`,`harga`,`dewasa`) values
(1,'Standard',400000,2),
(2,'Standard Big',800000,4),
(3,'Deluxe',800000,2),
(4,'Deluxe Big',1600000,4),
(5,'Suite',1600000,2),
(6,'Suite Big',3200000,4);
Ketika 'tgl di kalender komputer saya' itu sama dengan 'booking.checkin' Saya ingin mengupdate 'kamar.status' menjadi 'terpakai'. Terimkaasih
0
1 Jawaban:
Kalau menurut ane, pake cronjob namanya gan.
Jadi scriptnya auto jalan kita setting setiap jam 00.00 contoh-nya, tapi biasanya fitur ini ada di control panel hosting (cpanel, webuzo, dll)
Jadi kita buat script, nanti dia cek apabila hari server sama dengan hari booking, maka dia update jadi terpakai.
0