Home > database >  How to use distinct and selectCount function together in codeigniter 4?
How to use distinct and selectCount function together in codeigniter 4?

Time:10-07

i've no idea to write code in codeigniter 4 for use distinct and count function together

this is query : SELECT COUNT(DISTINCT(id_pm_satker))/49 FROM nilai_pm

CodePudding user response:

Regular Queries

To submit a query, use the query function:

$result = db_connect()
    ->query('SELECT COUNT(DISTINCT(id_pm_satker))/49 FROM nilai_pm;')
    ->getResultArray();

CodePudding user response:

If you are a little familiar with CI4 and you already have set up a Model for your table, let's say a NilaiPmModel, you can use it in your controller, like this:

$model = new \App\Models\NilaiPmModel();
$count = $model->distinct()->selectCount('id_pm_satker') / 49;
  • Related