// Get the columns
$columns = \DB::expr('COUNT('.($distinct ? 'DISTINCT ' : '').
\Database_Connection::instance($this->connection)->quote_identifier($select).
') AS count_result');
// Remove the current select and
$query = \DB::select($columns);
// Set from view or table
$query->from(array($this->_table(), $this->alias));
$tmp = $this->build_query($query, $columns, 'count');
$query = $tmp['query'];
$count = $query->execute($this->connection)->get('count_result');
It looks like you're new here. If you want to get involved, click one of these buttons!