I.m trying to check if a value exists in two columns from a table. The column names are on_number and off_number.
I've tried the following in my controller. The check works however for only the off_number columns and not the on_number.
my controller.
public function check()
{
$on_number = !empty(get('on_number')) ? get('on_number') : false;
$notId = !empty($this->input->get('notId')) ? $this->input->get('notId') : 0;
if($on_number)
$exists = count($this->duty_book_model->getByWhere([
'on_number' => $on__number,
'id !=' => $notId,
])) > 0 ? true : false;
if($on_number)
$exists = count($this->duty_book_model->getByWhere([
'off_number' => $on_number,
'id !=' => $notId,
])) > 0 ? true : false;
echo $exists ? 'false' : 'true';
}
My Model
class Duty_book_model extends MY_Model {
public $table = 'tbl_duty_type';
public function __construct()
{
parent::__construct();
}
}
The extends MY_Model has:
public function getByWhere($whereArg, $args = [])
{
if(isset($args['order']))
$this->db->order_by($args['order'][0], $args['order'][1]);
return $this->db->get_where($this->table, $whereArg)->result();
}
I would like it to check both columns if the value exists.