Welcome Guest, Not a member yet? Register   Sign In
Assist adding G-chart into my application
#1

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 ;
Reply
#2

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
Reply
#3

(11-12-2014, 02:15 AM)sv3tli0 Wrote: 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 ?

jUST want to know how to fetch data from DB and display on view
Reply
#4

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
Reply
#5

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 {
    public function 
get($id false)
    {
        if (
$id)
        {
            
$this->db->where('member_id'$id);
        }
        
$this->db->order_by('member_id''asc');
        
$query $this->db->get('member');
        if(
$query->num_rows() > 0)
        {
            return 
$query->result_array();
        }
        return 
false;
    }



Controller (Members.php
PHP Code:
class Members extends CI_Controller {

    public function 
__construct()
    {
        
parent::__construct();
        
$this->load->model('members_model');
    }

    public function 
index()
    {
        
$this->data['members'] = $this->members_model->get();
        
$this->load->view('members'$this->data);
    }




View (members.php)
PHP Code:
<?php foreach($members as $member): ?>
    <?php print_r($member); ?>
<?php 
endforeach; ?>

Reply




Theme © iAndrew 2016 - Forum software by © MyBB