1

How can I convert this mysqli_fetch_array in php to codeigniter?

$kueri7 = "SELECT ceil(count(kelas_id)/(select count(user_id) from tuser where matpel_id = $idmatpel)) as jumlah from tkelas";
$cocok8 = mysqli_query($con, $kueri7);
$cocok_kelas_maksimal = mysqli_fetch_array($cocok8);

Thanks in advance.

user1834095
  • 5,332
  • 2
  • 20
  • 38
241196
  • 33
  • 1
  • 1
  • 5
  • 1
    https://www.codeigniter.com/userguide3/database/queries.html & https://www.codeigniter.com/userguide3/database/results.html - check this one – Jaydp May 30 '18 at 04:19
  • (https://stackoverflow.com/questions/6047149/subquery-in-codeigniter-active-record) – Vijay Makwana May 30 '18 at 04:54

1 Answers1

0

With codeIgniter, your code would look like this:

$query = $this->db->query("SELECT ceil(count(kelas_id)/(select count(user_id) from tuser where matpel_id = $idmatpel)) as jumlah from tkelas", FALSE);
$cocok_kelas_maksimal = $query->result_array();
user1834095
  • 5,332
  • 2
  • 20
  • 38
Salim Ibrohimi
  • 1,351
  • 3
  • 17
  • 35