I'm working on Codeigniter rest API project and came across a problem. I would like my model not to select the data whose registration date is less than 01/01/2019 and whose types in the joined table equal type_1 type_2, but if the registration date is less than 2019 and the type in the joined table equals type_3, type_4 the request must return the record .
so i tried this method how can i get this result?
code: // MyModel
function get_data() {
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
if ($id != null) {
$this->db->where('ID',$id);
$result = $this->db->select('POST.ID,POST.DATE,'
. ' TYPE.Post_Type P_TYPE,)
->join('TYPE', 'POST.TYPE_ID = TYPE.ID', 'left')
->order_by('POST.ID', 'DESC')
->where_in('POST.Post_Type = type_1, type_2')
->where('POST.DATE<', "to_date('01/01/19', 'DD/MM/RR')", FALSE)
->get('POST');
}
return $result;
}
So i want that its not returning data with type_1 type_2 which are <than 2019, but can get others type
First, why did you filter in where post.date less than if you want greater than that date?. Second, where_in does accept values as an array on the second parameter. well here is my code, I reorganize your code to a much readable one. If you are trying to query date in timestamp or date field it should be in format of Y-m-d