[Solar-talk] limit in select

Jeff Surgeson solar at 3hex.com
Wed Jul 26 07:33:09 PDT 2006


Hi 

I am probably being stupid here but how do I limit the number of rows returned 
in a select or fetchAll call

I know that I can create a whole select query etc but I would have thought 
that I can do it using existing selct/fetch/fetchall functions just cant work 
out how

There is a limit() function in Solar_Sql_Select, but how do I use it in 
conjunction with a select or fetchAll call?

$this->list = $this->bd_news->fetchAll($where, $order, $page)->limit($limit) ?

Fatal error: Call to undefined method Solar_Sql_Rowset::limit()

How do I use limit method with a fetchAll or select call without creating a 
whole new select method like this to include a limit clause?

    public function select($type = 'result', $where = null,
        $order = null, $page = null, $limit = null)
    {
        $select = Solar::factory('Solar_Sql_Select');

        if ($type == 'all') {
            $class = $this->_all_class;
        } elseif ($type == 'row') {
            $class = $this->_row_class;
        } else {
            $class = null;
        }

        $result = $select->from($this->_name, array_keys($this->_col))
                         ->multiWhere($where)
                         ->order($order)
                         ->setPaging($this->_paging)
                         ->limitPage($page)
                         ->limit($limit)
                         ->fetch($type, $class);

        if ($result instanceof Solar_Sql_Row) {
            $result->setSave($this);
        }

        return $result;
    }

This works fine but ther must be a easier way.

Sorry if answer is obvious :-(

-- 
Jeff Surgeson

-- 
Jeff Surgeson


More information about the solar-talk mailing list