fuel/fuel/core/classes/database/connection.php
public function count_last_query()
	{
		if ($sql = $this->last_query)
		{
			$sql = trim($sql);
			if (stripos($sql, 'SELECT') !== 0)
			{
				return false;
			}

			if (stripos($sql, 'LIMIT') !== false)
			{
				// Remove LIMIT from the SQL
				$sql = preg_replace('/\sLIMIT\s+[^a-z]+/i', ' ', $sql);
			}

			if (stripos($sql, 'OFFSET') !== false)
			{
				// Remove OFFSET from the SQL
				$sql = preg_replace('/\sOFFSET\s+\d+/i', '', $sql);
			}

			// Get the total rows from the last query executed
			$result = $this->query
			(
				\DB::SELECT,
				'SELECT COUNT(*) AS '.$this->quote_identifier('total_rows').' '.
				'FROM ('.$sql.') AS '.$this->quote_table('counted_results'),
				true
			);

			// Return the total number of rows from the query
			return (int) $result->current()->total_rows;
		}

		return false;
	}
public function count_last_query()
	{
		if ($sql = $this->last_query)
		{
			$sql = trim($sql);
			if (stripos($sql, 'SELECT') !== 0)
			{
				return false;
			}

			if (stripos($sql, 'LIMIT') !== false)
			{
				// Remove LIMIT from the SQL
				$sql = preg_replace('/\sLIMIT\s+[^a-z]+/i', ' ', $sql);
			}

			if (stripos($sql, 'OFFSET') !== false)
			{
				// Remove OFFSET from the SQL
				$sql = preg_replace('/\sOFFSET\s+\d+/i', '', $sql);
			}

			// Get the total rows from the last query executed
			$result = $this->query
			(
				\DB::SELECT,
				'SELECT COUNT(*) AS '.$this->quote_identifier('total_rows').' '.
				'FROM ('.$sql.') AS '.$this->quote_table('counted_results'),
				true
			);

			// Return the total number of rows from the query
			return (int) $result->current()->total_rows;
		}

		return false;
	}
public function count_last_query ( ) { if ( $ sql = $ this -> last_query ) { $ sql = trim ( $ sql ) ; if ( stripos ( $ sql , 'SELECT' ) !== 0 ) { return false ; } if ( stripos ( $ sql , 'LIMIT' ) !== false ) { // Remove LIMIT from the SQL $ sql = preg_replace ( '/\sLIMIT\s+[^a-z]+/i' , ' ' , $ sql ) ; } if ( stripos ( $ sql , 'OFFSET' ) !== false ) { // Remove OFFSET from the SQL $ sql = preg_replace ( '/\sOFFSET\s+\d+/i' , '' , $ sql ) ; } // Get the total rows from the last query executed $ result = $ this -> query ( \ DB :: SELECT , 'SELECT COUNT(*) AS ' . $ this -> quote_identifier ( 'total_rows' ) . ' ' . 'FROM (' . $ sql . ') AS ' . $ this -> quote_table ( 'counted_results' ) , true ) ; // Return the total number of rows from the query return ( int ) $ result -> current ( ) -> total_rows ; } return false ; }
Count the number of records in the last query, without LIMIT or OFFSET applied.

// Get the total number of records that match the last query
$count = $db->count_last_query();

@return  integer
Count the number of records in the last query without LIMIT or OFFSET applied .