title: How to display the frequency count in several mysql tables in codeigniter
body: <p>How can I display the frequency of the number of students in a class. I have several tables in the database.</p>
  
  <p>table = kelas</p>
  
  <pre><code>+----+---------+---------+
  | id | tingkat | nama    |
  +----+---------+---------+
  |  1 |       5 | Kelas 5 |
  |  2 |       3 | Kelas 3 |
  +----+---------+---------+
  </code></pre>
  
  <p>table = siswa</p>
  
  <pre><code>+----+----------+
  | id |   nama   |
  +----+----------+
  |  1 |        1 |
  |  2 |        1 |
  |  3 |        1 |
  |  4 |        1 |
  etc.
  </code></pre>
  
  <p>table = kelas_siswa</p>
  
  <pre><code>+----+----------+----------+------+
  | id | id_kelas | id_siswa | ta   |
  +----+----------+----------+------+
  | 18 |        1 |       18 | 2019 |
  | 19 |        1 |       19 | 2019 |
  | 20 |        1 |       20 | 2019 |
  | 21 |        1 |       21 | 2019 |
  | 22 |        1 |       22 | 2019 |
  | 23 |        1 |       23 | 2019 |
  | 24 |        1 |       24 | 2019 |
  | 25 |        1 |       25 | 2019 |
  | 26 |        1 |       26 | 2019 |
  | 27 |        1 |       27 | 2019 |
  | 28 |        1 |       28 | 2019 |
  | 29 |        1 |       29 | 2019 |
  | 30 |        1 |       30 | 2019 |
  | 31 |        1 |       31 | 2019 |
  |  1 |        2 |        1 | 2019 |
  |  2 |        2 |        2 | 2019 |
  |  3 |        2 |        3 | 2019 |
  |  4 |        2 |        4 | 2019 |
  |  5 |        2 |        5 | 2019 |
  |  6 |        2 |        6 | 2019 |
  |  7 |        2 |        7 | 2019 |
  |  8 |        2 |        8 | 2019 |
  |  9 |        2 |        9 | 2019 |
  | 10 |        2 |       10 | 2019 |
  | 11 |        2 |       11 | 2019 |
  | 12 |        2 |       12 | 2019 |
  | 13 |        2 |       13 | 2019 |
  | 14 |        2 |       14 | 2019 |
  | 15 |        2 |       15 | 2019 |
  | 16 |        2 |       16 | 2019 |
  | 17 |        2 |       17 | 2019 |
  +----+----------+----------+------+
  </code></pre>
  
  <p>How do I display data on the number of students for kelas 3 and kelas 5. on :</p>
  
  <pre><code>.$JUMLAH_SISWA.
  </code></pre>
  
  <p>For example Class 3 there are 17 students and Class 5 there are 14 Students</p>
  
  <pre class="lang-php prettyprint-override"><code>public function index() {
          $d=array();
          $ambil_data_kelas = $this-&gt;db-&gt;query("SELECT id, nama FROM m_kelas ORDER BY tingkat ASC, nama ASC")-&gt;result_array();
  
          $tampil = "";
          if (!empty($ambil_data_kelas)) {
              foreach ($ambil_data_kelas as $v) {
                  $tampil .= '&lt;div class="col-md-4"&gt;&lt;div class="panel panel-info"&gt;
                                  &lt;div class="panel-heading"&gt;&lt;b&gt;'.$v['nama'].' jumlah siswa : '.$JUMLAH_SISWA.'&lt;/b&gt;&lt;/div&gt;
                                  &lt;div class="panel-body" style="height: 300px; overflow: auto"&gt;
                                  &lt;table class="table table-stripped"&gt;
                                      &lt;thead&gt;
                                          &lt;tr&gt;&lt;th&gt;No&lt;/th&gt;&lt;th&gt;Nama&lt;/th&gt;&lt;th&gt;Aksi&lt;/th&gt;&lt;/tr&gt;
                                      &lt;/thead&gt;
                                      &lt;tbody&gt;';
  
                  $q_siswa_per_kelas = $this-&gt;db-&gt;query("SELECT 
  
                                                          a.id, b.nama nmsiswa, a.id_kelas
                                                          FROM t_kelas_siswa a
                                                          INNER JOIN m_siswa b ON a.id_siswa = b.id
                                                          WHERE a.id_kelas = '".$v['id']."' 
                                                          AND a.ta = '".$this-&gt;d['ta']."'
                                                          ORDER BY b.nis ASC, b.nama ASC")-&gt;result_array();
  
  
  
                  if (!empty($q_siswa_per_kelas)) {
                      $no = 1;
                      foreach ($q_siswa_per_kelas as $k) {
                          $tampil .= '&lt;tr&gt;&lt;td&gt;'.$no++.'&lt;/td&gt;&lt;td&gt;'.$k['nmsiswa'].'&lt;/td&gt;&lt;td class="ctr"&gt;&lt;a href="#" onclick="return hapus('.$k['id'].');" class="btn btn-danger btn-xs"&gt;&lt;i class="fa fa-remove"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;';
                      }
                  }
  
                  $tampil .= '&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;';
              }
          }
  
          $this-&gt;d['tampil'] = $tampil;
          $this-&gt;d['p'] = "list";
          $this-&gt;load-&gt;view("template_utama", $this-&gt;d);
      }
  </code></pre>