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);
