Welcome Guest, Not a member yet? Register   Sign In
ion_auth messing up my query


$user = $this->ion_auth->user()->row();
$this->db->where('appt_date >=', $FromAppt_Date);
$this->db->where('appt_date<=', $ToAppt_Date);
$group = 'Requester';
        if ($this->ion_auth->in_group($group)) {
            $this->db->where('department_code', $user->department_code);
$query = $this->db->get('table');

Unknown column 'appt_date' in 'where clause'

SELECT `users_groups`.`group_id` as `id`, `groups`.`name`, `groups`.`description` FROM `users_groups` JOIN `groups` ON `users_groups`.`group_id`=`groups`.`id` WHERE `appt_date` >= '2017-06-12' AND `appt_date` <= '2017-06-12' AND `users_groups`.`user_id` = '1'
Above fails because query is trying to select query based on ion_table

If that is the case you can use

PHP Code:

To clear all the settings before starting to use the query builder. This will fix the issue but not the cause of the issue.

Actually re-reading your issue, it is the call to ion_auth inside your query builder clauses. If ion_auth runs a query now you will lose your original db lines in your query as they will get reset.

Perhaps you should try getting your user group variable out before creating your db query. Something like:

PHP Code:
$user $this->ion_auth->user()->row();

$check_department = ($this->ion_auth->in_group('Requester')) ? TRUE FALSE;

$this->db->where('appt_date >='$FromAppt_Date);
if (
$query $this->db->get('table'); 

Best wishes,


Thank you Paul. I will try this today.

Theme © iAndrew 2016 - Forum software by © MyBB