Index: /branches/release-35/php/lib/mtdb_base.php
===================================================================
--- /branches/release-35/php/lib/mtdb_base.php (revision 1800)
+++ /branches/release-35/php/lib/mtdb_base.php (revision 1911)
@@ -2004,17 +2004,17 @@
         }
 
-        $order = 'desc';
+        $order = $query_order = 'desc';
         if (isset($args['sort_order'])) {
             if ($args['sort_order'] == 'ascend') {
-                $order = 'asc';
+                $order = $query_order = 'asc';
             }
         } elseif (isset($blog) && isset($blog['blog_sort_order_comments'])) {
             if ($blog['blog_sort_order_comments'] == 'ascend') {
-                $order = 'asc';
-            }
-        }
-        if ($order == 'asc' && $args['lastn']) {
+                $order = $query_order = 'asc';
+            }
+        }
+        if ($order == 'asc' && (isset($args['lastn']) || isset($args['offset']))) {
             $reorder = 1;
-            $order = 'desc';
+            $query_order = 'desc';
         }
 
@@ -2041,5 +2041,5 @@
             $limit = $args['limit'];
         if (isset($args['offset']))
-            $limit = $args['offset'];
+            $offset = $args['offset'];
         if (count($filters)) {
             $post_select_limit = $limit;
@@ -2058,7 +2058,8 @@
                    $entry_filter
                    $blog_filter
-             order by comment_created_on $order
+             order by comment_created_on $query_order
                    <LIMIT>";
         $sql = $this->apply_limit_sql($sql, $limit, $offset);
+
         # Fetch resultset
         $result = $this->query_start($sql);
@@ -2066,7 +2067,7 @@
 
         $comments = array();
+        $j = 0;
         while (true) {
             $e = $this->query_fetch(ARRAY_A);
-            if ($offset && ($j++ < $offset)) continue;
             if (!isset($e)) break;
             if (count($filters)) {
@@ -2074,7 +2075,8 @@
                     if (!$f($e, $ctx)) continue 2;
                 }
+                if ($post_select_offset && ($j++ < $post_select_offset)) continue;
+                if (($post_select_limit > 0) && (count($comments) >= $post_select_limit)) break;
             }
             $comments[] = $e;
-            if (($limit > 0) && (count($comments) >= $limit)) break;
         }
 
@@ -2124,5 +2126,5 @@
             return array();
 
-        if ($reorder) {  // lastn and ascending sort
+        if ($reorder && !isset($args['sort_by'])) {  // lastn and ascending sort
             $asc_created_on = create_function('$a,$b', 'return strcmp($a["comment_created_on"], $b["comment_created_on"]);');
             usort($comments, $asc_created_on);
Index: /branches/release-35/lib/MT/Template/ContextHandlers.pm
===================================================================
--- /branches/release-35/lib/MT/Template/ContextHandlers.pm (revision 1906)
+++ /branches/release-35/lib/MT/Template/ContextHandlers.pm (revision 1911)
@@ -5058,14 +5058,31 @@
     if ($comments) {
         my $n = $args->{lastn};
+        my $col = lc($args->{sort_by} || 'created_on');
+        @$comments = $so eq 'ascend' ?
+            sort { $a->$col() cmp $b->$col() } @$comments :
+            sort { $b->$col() cmp $a->$col() } @$comments;
+        $no_resort = 1;
         if (@filters) {
+            my $offset = $args->{offset} || 0;
+            my $j      = 0;
             COMMENTS: for my $c (@$comments) {
                 for (@filters) {
                     next COMMENTS unless $_->($c);
                 }
+                next if $offset && $j++ < $offset;
                 push @comments, $c;
             }
         }
         else {
-            @comments = @$comments;
+            my $offset;
+            if ($offset = $args->{offset}) {
+                if ($offset < scalar @comments) {
+                    @comments = @$comments[$offset..$#comments];
+                } else {
+                    @comments = ();
+                }
+            } else {
+                @comments = @$comments;
+            }
             $no_resort = 1
                 unless $args->{sort_order} || $args->{sort_by};
@@ -5091,19 +5108,33 @@
             $args{'sort'} = 'created_on';
             $args{'direction'} = 'descend';
-            my $comments = $e->comments(\%terms, \%args);
-            my $i = 0;
+            my $cmts = $e->comments(\%terms, \%args);
+            my $offset = $args->{offset} || 0;
             if (@filters) {
-                COMMENTS: for my $c (@$comments) {
+                my $i = 0;
+                my $j = 0;
+                my $offset = $args->{offset} || 0;
+                COMMENTS: for my $c (@$cmts) {
                     for (@filters) {
                         next COMMENTS unless $_->($c);
                     }
+                    next if $offset && $j++ < $offset;
                     push @comments, $c;
                     last if $n && ( $n <= ++$i );
                 }
-            } elsif ($n) {
-                my $max = $n - 1 > $#$comments ? $#$comments : $n - 1;
-                @comments = @$comments[0..$max];
+            } elsif ($offset || $n) {
+                if ($offset) {
+                    if ($offset < scalar @$cmts - 1) {
+                        @$cmts = @$cmts[$offset..(scalar @$cmts - 1)];
+                     } else {
+                        @$cmts = ();
+                    }
+                }
+                if ($n) {
+                    my $max = $n - 1 > scalar @$cmts - 1 ? scalar @$cmts - 1 : $n - 1;
+                    @$cmts = @$cmts[0..$max];
+                }
+                @comments = @$cmts;
             } else {
-                @comments = @$comments;
+                @comments = @$cmts;
             }
         } else {
@@ -5114,4 +5145,5 @@
             if (!@filters) {
                 $args{limit} = $n if $n;
+                $args{offset} = $args->{offset} if $args->{offset};
                 $args{join} = MT->model('entry')->join_on(
                     undef,
@@ -5125,4 +5157,6 @@
                 my $iter = MT::Comment->load_iter(\%terms, \%args);
                 my %entries;
+                my $j = 0;
+                my $offset = $args->{offset} || 0;
                 COMMENT: while (my $c = $iter->()) {
                     my $e = $entries{$c->entry_id} ||= $c->entry;
@@ -5132,4 +5166,5 @@
                         next COMMENT unless $_->($c);
                     }
+                    next if $offset && $j++ < $offset;
                     push @comments, $c;
                     if ($n && (scalar @comments == $n)) {
