Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*********************************
- FILENAME : psb.php
- CREATE BY : cahya dsn
- PURPOSE : calculate support value
- CREATE DATE : 2012-12-31
- **********************************
- #table creation
- USE `test`;
- DROP TABLE IF EXISTS `tbl_psb`;
- CREATE TABLE IF NOT EXISTS `tbl_psb` (
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key untuk table tbl_psb',
- `nilai` varchar(2) NOT NULL COMMENT 'nilai',
- `jalur_masuk` varchar(4) NOT NULL COMMENT 'jalur masuk',
- `count` int(11) unsigned NOT NULL DEFAULT 0,
- PRIMARY KEY(`id`)
- ) ENGINE=MyISAM COMMENT='tabel untuk menyimpan data PSB';
- INSERT INTO `tbl_psb`(`id`,`nilai`,`jalur_masuk`,`count`) VALUES
- (NULL,'A2','PSSB',3),
- (NULL,'A2','SPMB',1),
- (NULL,'A3','PSSB',2),
- (NULL,'A3','SPMB',3);
- */
- //database configuration
- $dbhost='localhost';
- $dbuser='root';
- $dbpass='';
- $dbname='test';
- //database connection
- $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
- //query to get organization datas from database
- $sql="SELECT nilai,jalur_masuk,count,(count/jml) AS support "
- ."FROM tbl_psb, "
- ."(SELECT nilai AS nilai2,SUM(count) AS jml "
- ." FROM tbl_psb "
- ." GROUP BY nilai "
- .") AS t2 "
- ."WHERE count>2 "
- ."AND nilai2=nilai";
- $result=$db->query($sql);
- echo "<pre>"
- ."Nilai | Jalur Masuk | Count | Support |\n";
- while($records=$result->fetch_object()){
- echo str_pad($records->nilai,6,' ',STR_PAD_BOTH)."|";
- echo str_pad($records->jalur_masuk,13,' ',STR_PAD_BOTH)."|";
- echo str_pad($records->count,7,' ',STR_PAD_BOTH)."|";
- echo str_pad($records->support,9,' ',STR_PAD_BOTH)."|\n";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement