$perPage = 1;
$start = intval($this->request['st']);
$this->DB->build( array( 'select' => 'count(*) as page', 'from' => 'topics', 'where' => 'important=1', 'limit' => array( $start, $perPage ) ));
$this->DB->execute();
$count = $this->DB->fetch($result);
$pages = $this->registry->getClass('output')->generatePagination( array( 'totalItems' => $count['page'],
'itemsPerPage' => $perPage,
'currentStartValue' => $start,
'baseUrl' => '&st=' . $this->request['st'] ) );
$rs = $this->DB->build( array(
'select' => 't.*',
'from' => array( 'topics' => 't' ),
'where' => 't.important=1',
'order' => 't.tid DESC',
'limit' => array( $start, $perPage ), 'add_join' => array(
'add_join' => array(
'select' => 'p.*',
'from' => array( 'posts' => 'p' ),
'where' => 't.tid=p.topic_id AND p.new_topic=1',
'type' => 'left',
), ) ) );