Create Table
CREATE TABLE IF NOT EXISTS `daily` (
`id` int(5) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL,
`name` varchar(64) NOT NULL,
`amount` double NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
Insert
INSERT INTO `daily` (`id`, `date`, `name`, `amount`) VALUES
(1, '2012-02-21', 'Kenshin', 5000),
(2, '2012-02-21', 'Naruto', 6000),
(3, '2012-02-21', 'Lufy', 7000),
(4, '2012-02-21', 'Zoro', 8000),
(5, '2012-02-21', 'Franky', 9000);
Controller
application\controllers\welcome.php
1 2 3 4 5 6 7 8 9 10 11 12 | <?php class Welcome extends CI_Controller { function index(){ $this ->load->library( 'table' ); $this ->load->database(); $data [ 'records' ]= $this ->db->get( 'daily' ); $header = array ( 'ID' , 'Date' , 'Name' , 'Amount' ); $this ->table->set_heading( $header ); $this ->load->view( 'welcome/index' , $data ); } } |
views\welcome\index.php
1 2 3 4 5 6 | <div id= "container" > <h1>Welcome to CodeIgniter!</h1> <div id= "body" > <?php echo $this ->table->generate( $records ); ?> </div> </div> |