title: How to convert my Native PHP Code to Codeigniter code
body: <p>I want to convert my native php code about graphical statistic, the chart is filled with total amount of student per class, im using chart.js for my statistic , please help me to convert my code to the CodeIgniter code guys, Thanks.</p>
  
  <p>i'ver been try to put all folder and code to controller, but nothing show. and i dont know how to convert it to CI.</p>
  
  <p>this is my koneksi.php code : </p>
  
  <pre><code>&lt;?php
      $koneksi = mysqli_connect("localhost","root","","grafik_mahasiswa");
  ?&gt;
  </code></pre>
  
  <p>And this is my index.php code :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Test and Try&lt;/title&gt;
      &lt;script type="text/javascript" src="chartjs/Chart.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;style type="text/css"&gt;
      body{
          font-family: roboto;
      }
  
      table{
          margin: 0px auto;
      }
      &lt;/style&gt;
  
  
      &lt;center&gt;
          &lt;h2&gt;Try me&lt;/h2&gt;
      &lt;/center&gt;
  
  
      &lt;?php 
      include 'koneksi.php';
      ?&gt;
  
      &lt;div style="width: 800px;margin: 0px auto;"&gt;
          &lt;canvas id="myChart"&gt;&lt;/canvas&gt;
      &lt;/div&gt;
  
      &lt;br/&gt;
      &lt;br/&gt;
  
      &lt;table border="1"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;No&lt;/th&gt;
                  &lt;th&gt;Nama Mahasiswa&lt;/th&gt;
                  &lt;th&gt;NIM&lt;/th&gt;
                  &lt;th&gt;Fakultas&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              &lt;?php 
              $no = 1;
              $data = mysqli_query($koneksi,"select * from mahasiswa");
              while($d=mysqli_fetch_array($data)){
                  ?&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;?php echo $no++; ?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo $d['nama']; ?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo $d['nim']; ?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo $d['fakultas']; ?&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;?php 
              }
              ?&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  
  
      &lt;script&gt;
          var ctx = document.getElementById("myChart").getContext('2d');
          var myChart = new Chart(ctx, {
              type: 'bar',
              data: {
                  labels: ["Teknik", "Fisip", "Ekonomi", "Pertanian"],
                  datasets: [{
                      label: '',
                      data: [
                      &lt;?php 
                      $jumlah_teknik = mysqli_query($koneksi,"select * from mahasiswa where fakultas='teknik'");
                      echo mysqli_num_rows($jumlah_teknik);
                      ?&gt;, 
                      &lt;?php 
                      $jumlah_ekonomi = mysqli_query($koneksi,"select * from mahasiswa where fakultas='ekonomi'");
                      echo mysqli_num_rows($jumlah_ekonomi);
                      ?&gt;, 
                      &lt;?php 
                      $jumlah_fisip = mysqli_query($koneksi,"select * from mahasiswa where fakultas='fisip'");
                      echo mysqli_num_rows($jumlah_fisip);
                      ?&gt;, 
                      &lt;?php 
                      $jumlah_pertanian = mysqli_query($koneksi,"select * from mahasiswa where fakultas='pertanian'");
                      echo mysqli_num_rows($jumlah_pertanian);
                      ?&gt;
                      ],
                      backgroundColor: [
                      'rgba(255, 99, 132, 0.2)',
                      'rgba(54, 162, 235, 0.2)',
                      'rgba(255, 206, 86, 0.2)',
                      'rgba(75, 192, 192, 0.2)'
                      ],
                      borderColor: [
                      'rgba(255,99,132,1)',
                      'rgba(54, 162, 235, 1)',
                      'rgba(255, 206, 86, 1)',
                      'rgba(75, 192, 192, 1)'
                      ],
                      borderWidth: 1
                  }]
              },
              options: {
                  scales: {
                      yAxes: [{
                          ticks: {
                              beginAtZero:true
                          }
                      }]
                  }
              }
          });
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>