I have a CodeIgniter query with the following lines.
$userloc = $this->session->userdata('location');
$query = $this->db->query('
select assettype,
sum(status="In Stock")In_stock,
sum(status = "Allocated")Allocated,
sum(status = "Decommission")Decommission,
sum(status = "In transit")In_Transit,
location
from assets
group by assettype, location
');
I want to put a LIKE condition in the $query
where location LIKE $userloc
, but my attempts are not working out.
Try using below
$this->db->select('assettype,sum(status="In Stock")In_stock,sum(status = "Allocated")Allocated,sum(status = "Decommission") Decommission,sum(status = "In transit")In_Transit,location');
$this->db->from('assets');
$this->db->like('location', $userloc);
$this->db->group_by('assettype,location');
$query = $this->db->get();