mardi 31 août 2021

CodeIgniter - SQL sentence IF then WHERE?

Currently I am capable of doing WHERE sentences in CodeIgniter as follows:

$builder = $db->table('mytable');
$builder->select(*);
$builder->where('age >='.$params['some-param']);

What I need to do, is a WHERE statement that only applies if an IF statement is true. Something like:

(IF gender = 'Male', apply these rows the following where) $builder->where('age >='.$params['some-param']);
(IF gender = 'Female', apply these other rows, this where and not the first one) $builder->where('age >='.$params['some-other-param']);

I have no clue of how to achieve this. Any orientation will be appreciated.

Aucun commentaire:

Enregistrer un commentaire