Skip to content
Advertisement

How to use between clause in select statement in codeigneiter

I’m trying to get data from database by taking one data row from one table and use those values as where condition. and then i tried pass json string to controller class. but i’m unable to reach this. how should i write this code This is code i used to get data.

 $query = $this->db->query("SELECT * FROM todaywork WHERE idEmployee = $user ");

        if ($query->num_rows() > 0)
        {
           $row = $query->row(); 

               $from = $row->T_frange;
               $to = $row->T_trange;
               $note = $row->T_note;
        }     
               $this->db->select("cus.idCustomer,cus.C_name,f.F_itemname,ctr.*");
                //$whereCondition = array('cus.idCustomer' => $_POST['custId']);
                $this->db->where('C_trnoofarr BETWEEN {$from} AND {$to}');
                //filter where
                $this->db->from('customer cus');
                $this->db->join('contracts AS ctr', 'cus.idCustomer = ctr.idCustomer', 'INNER');
                $this->db->join('facility AS f','ctr.idContracts = f.idContracts','INNER');
                $query = $this->db->get();

                return $query->result();

    }

Advertisement

Answer

Use this for between

$this->db->where('C_trnoofarr >', $from);
$this->db->where('C_trnoofarr <', $to);
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement