Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- USE test;
- DROP TABLE IF EXISTS tbl_aspek;
- CREATE TABLE IF NOT EXISTS tbl_aspek(
- id_aspek TINYINT(3) UNSIGNED AUTO_INCREMENT,
- aspek VARCHAR(100) NOT NULL,
- prosentase FLOAT NOT NULL,
- PRIMARY KEY(id_aspek)
- )ENGINE=MyISAM;
- INSERT INTO tbl_aspek(id_aspek,aspek,prosentase)
- VALUES
- (1,'Kecerdasan',20),
- (2,'Sikap Kerja',30),
- (3,'Perilaku',50);
- DROP TABLE IF EXISTS tbl_faktor;
- CREATE TABLE IF NOT EXISTS tbl_faktor(
- id_faktor SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
- id_aspek TINYINT(3) UNSIGNED NOT NULL,
- faktor VARCHAR(100) NOT NULL,
- nilai TINYINT(3) NOT NULL,
- kelompok SET('core','secondary'),
- PRIMARY KEY(id_faktor)
- )ENGINE=MyISAM;
- INSERT INTO tbl_faktor(id_faktor,id_aspek,faktor,nilai,kelompok)
- VALUES
- (1,1,'Common Sense',3,'core'),
- (2,1,'Verbalisasi Ide',3,'core'),
- (3,1,'Sistematika berpikir',4,'secondary'),
- (4,1,'Penalaran dan Solusi Real',4,'secondary'),
- (5,1,'Konsentrasi',3,'core'),
- (6,1,'Logika Praktis',4,'secondary'),
- (7,1,'Fleksibilitas Berpikir',4,'secondary'),
- (8,1,'Imajinasi Kreatif',5,'core'),
- (9,1,'Antisipasi',3,'core'),
- (10,1,'Potensi Kecerdasan',4,'secondary'),
- (11,2,'Energi Psikis',3,'core'),
- (12,2,'Ketelitian dan Tanggung jawab',4,'core'),
- (13,2,'Kehati-hatian',2,'secondary'),
- (14,2,'Pengendalian Perasaan',3,'secondary'),
- (15,2,'Dorongan berprestasi',3,'core'),
- (16,2,'Vitalitas Perencanaan',5,'secondary'),
- (17,3,'Kekuasaan (Dominance)',3,'core'),
- (18,3,'Pengaruh (Influence)',3,'core'),
- (19,3,'Keteguhan Hati (Steadiness)',4,'secondary'),
- (20,3,'Pemenuhan (Compliance)',5,'secondary');
- */
- $dbhost='localhost';
- $dbuser='root';
- $dbpass='';
- $dbname='test';
- $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
- if(isset($_POST['id_aspek'])){
- $sql="SELECT * FROM tbl_faktor WHERE id_aspek='{$_POST['id_aspek']}'";
- $result=$db->query($sql);
- $faktor='';
- while($row=$result->fetch_object()){
- $faktor.="<option value='{$row->id_faktor}'>{$row->faktor}</option>";
- }
- $result->free();
- }
- ?>
- <!doctype html>
- <html>
- <head>
- <title>Chainned Combobox</title>
- </head>
- <body>
- <form method='post'>
- <select name='id_aspek'>
- <?php
- $sql="SELECT * FROM tbl_aspek";
- $result=$db->query($sql);
- while($row=$result->fetch_object()){
- echo "<option value='{$row->id_aspek}'"
- .(isset($_POST['id_aspek']) && $row->id_aspek==$_POST['id_aspek']?" selected='selected'":"")
- .">{$row->aspek}</option>";
- }
- ?>
- </select>
- <select name='id_faktor'>
- <?php echo isset($faktor)?$faktor:'';?>
- </select>
- <input type='submit'>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement