public static function _getGrid ($params = array (), $relations = array (), &$db = FALSE)
	{
		
		// If no limit has been set

		if (!$params || !isset ($params['limit']))
		{

			// Set default query limit
			
			$params['limit'] = array (0, 50);

		}
		
		// Get data
		
		if ($relations)
		{
			
			$objs	= static::_getObjects ($params, $db);
			$data	= array ();
			
			foreach ($objs as $obj)
			{
				
				$attributes	= is_array ($params['select'])? $params['select'] : explode (',', $params['select']);
				
				foreach ($attributes as &$val)
				{
					$val = trim ($val);
				}
				
				$data[] = $obj->toArray ($attributes, $relations);
				
			}
			
		}
		else
		{
			$data	= static::_getValues ($params, $db);
		}
		
		// Get count
		
		$count	= self::_count ($params, $db);

		// If there was a problem return FALSE

		if ($count === FALSE || $data === FALSE)
		{
			return FALSE;
		}
		
		// Add class (for API XML response)
		
		$class	= self::_getClass ();
		
		foreach ($data as &$row)
		{
			$row['class']	= $class;
		}
		
		// Return grid
		
		return array (
			'total'	=> $count,
			'rows'	=> $data
		);

	}