Assist adding G-chart into my application |
Assist adding G-chart into my application
I want to create Charts i am using G-Charts but the charts doesnt show I want chart to fetch information from province in my database Controller public function column_chart_basic(){ $this->gcharts->load('ColumnChart'); $this->gcharts->DataTable('provinces') ->addColumn('string', 'Membership', 'member') ->addColumn('number', 'Eastern Cape', 'eastern cape') ->addColumn('number', 'Free State', 'free state') ->addColumn('number', 'Gauteng', 'gauteng') ->addColumn('number', 'Kwa-Zulu Natal', 'kwa-zulu natal') ->addColumn('number', 'Limpopo', 'limpopo') ->addColumn('number', 'Mpumalanga', 'mpumalanga') ->addColumn('number', 'Northern Cape', 'northern cape') ->addColumn('number', 'North West', 'north west') ->addColumn('number', 'Western Cape', 'western cape') ->addRow(array( 'Membership', rand(50, 100), rand(50, 100), rand(50, 100), rand(50, 100), rand(50, 100), rand(50, 100), rand(50, 100) )); $config = array( 'title' => 'Member' ); View <div class="box-content padded"> <?php echo $this->gcharts->ColumnChart('provinces')->outputInto('provinces_div'); echo $this->gcharts->div(600, 500); if($this->gcharts->hasErrors()) { echo $this->gcharts->getErrors(); } ?> </div> DATABASE -- -- Table structure for table `member` -- CREATE TABLE IF NOT EXISTS `member` ( `member_id` int(16) NOT NULL AUTO_INCREMENT, `membershipno` int(16) DEFAULT NULL, `firstnames` varchar(50) NOT NULL, `lastname` varchar(50) NOT NULL, `intial` varchar(10) NOT NULL, `title` varchar(50) NOT NULL, `id_number` int(13) DEFAULT NULL, `Passport_No` varchar(15) DEFAULT NULL, `dateofbirth` date NOT NULL, `gender` varchar(10) NOT NULL, `phone` varchar(10) NOT NULL, `email` varchar(50) DEFAULT NULL, `address1` varchar(50) NOT NULL, `address2` varchar(50) DEFAULT NULL, `address3` varchar(50) DEFAULT NULL, `city` varchar(50) NOT NULL, `Province` varchar(50) NOT NULL `country` varchar(50) NOT NULL, `postalcode` varchar(4) DEFAULT NULL, `branch` varchar(50) NOT NULL, `type` varchar(50) NOT NULL, `join_date` date NOT NULL, `expiry` date NOT NULL, `status` varchar(50) NOT NULL, `discount` varchar(50) NOT NULL, PRIMARY KEY (`member_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
1st of all please use the BBcode code for better syntax of your thread.
In your case do you need CRUD system for managing this DB table and displaying the g-chart or you want just to know how to fetch data from the DB so you can generate the chart ? Best VPS Hosting : Digital Ocean
(11-12-2014, 02:15 AM)sv3tli0 Wrote: 1st of all please use the BBcode code for better syntax of your thread. jUST want to know how to fetch data from DB and display on view
Read http://www.codeigniter.com/user_guide/ge...odels.html - Models documentation.
1st. You have to create 1 model called lets say Gchart. 2nd. Inside it create a method who will return the data from DB. 3rd. Using DB queries ( http://www.codeigniter.com/user_guide/da...index.html ) you can fetch data in the way you need it. 4th. At your Controller method load the model and call the method. * To use DB you must enter first your DB setting at config.php Best VPS Hosting : Digital Ocean
Here are a simple example for fetching data and print it in the view.
Model (Members_model.php) PHP Code: class Members extends CI_Model { Controller (Members.php PHP Code: class Members extends CI_Controller { View (members.php) PHP Code: <?php foreach($members as $member): ?> |
Welcome Guest, Not a member yet? Register Sign In |