Код: Выделить всё
public function getItemSale($start, $end = 9,$userid,$loc_id,$item)
{
$sql = "SELECT Name, sum(Qty) as total, sum(Price) as sale from itransfile where
SESSIONID = GETSESSIONID(?) && PayMode IN('CASH','Cheque')";
if(is_numeric($loc_id))
$sql .= " && location_id = " .$loc_id;
else
$sql .= " && location_id IN(SELECT location_id FROM client_locations where client_id = " .$userid. ")";
if($item != 'All')
$sql .= " && Name = `{$item}`";
$sql .= " group by Name order by sale desc LIMIT ? OFFSET ?;";
$query = $this->db->query($sql, array(date("Y-m-d"),$end,(int)$start));
return $query->result_array();
}

Подробнее здесь: https://stackoverflow.com/questions/303 ... pped-in-ba