我有一个包含以下几行的 CodeIgniter 查询。
$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
');
我想在
$query
处放置一个 LIKE 条件,其中 location LIKE $userloc
,但我的尝试没有成功。
试试这个:
$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 where location like "%'.$userloc.'%" group by assettype,location');
尝试使用以下
$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();
尝试以下查询:
$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 where location like %$userloc% group by assettype,location');
使用以下查询
$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 where location like '%$userloc%' group by assettype,location');