Index: uc_attribute.admin.inc
===================================================================
--- uc_attribute.admin.inc	(revision 84)
+++ uc_attribute.admin.inc	(working copy)
@@ -1038,10 +1038,6 @@
 
   //Populate table and such.
   $model = $node->model;
-  $query_select = "SELECT DISTINCT";
-  $query_from = " FROM";
-  $query_where = " WHERE";
-  $query_order = " ORDER BY";
   $result = db_query("SELECT pa.nid, pa.aid, pa.ordering, pa.display, a.name, a.ordering, ao.aid, COUNT(po.oid) FROM {uc_product_attributes} AS pa LEFT JOIN {uc_attributes} AS a ON pa.aid = a.aid LEFT JOIN {uc_attribute_options} AS ao ON a.aid = ao.aid LEFT JOIN {uc_product_options} AS po ON ao.oid = po.oid AND po.nid = %d WHERE pa.nid = %d AND pa.display <> 3 GROUP BY ao.aid, pa.aid, pa.display, a.name, pa.ordering, a.ordering, pa.nid HAVING count(po.oid) > 0 ORDER BY pa.ordering, a.ordering", $nid, $nid);
   $i = 1;
   $attribute_names = '';
@@ -1049,23 +1045,11 @@
   $values = array();
 
   while ($prod_attr = db_fetch_object($result)) {
-    $query_select .= " ao$i.aid AS aid$i, ao$i.name AS name$i, ao$i.oid AS oid$i, po$i.ordering,";
-    $query_from .= " ({uc_product_options} AS po$i LEFT JOIN {uc_attribute_options} AS ao$i ON po$i.oid = ao$i.oid AND po$i.nid = %d),";
-    $values[] = $nid;
-    $query_where .= " ao$i.aid = ". $prod_attr->aid ." AND";
-    $query_order .= " po$i.ordering, ao$i.name,";
-    ++$i;
     $attribute_names .= '<th>'. check_plain($prod_attr->name) .'</th>';
     $attribute_ids[] = $prod_attr->aid;
   }
   $num_prod_attr = count($attribute_ids);
 
-  // Remove last connecting parts (commas, "AND")
-  $query_select = rtrim($query_select, ',');
-  $query_from = rtrim($query_from, ',');
-  $query_where = substr($query_where, 0, strlen($query_where) - 4);
-  $query_order = rtrim($query_order, ',');
-
   if ($num_prod_attr) {
     //Get previous values
     $result = db_query("SELECT * FROM {uc_product_adjustments} WHERE nid = %d", $nid);
@@ -1074,7 +1058,34 @@
       $old_vals[] = $obj;
     }
 
-    $result = pager_query($query_select . $query_from . $query_where . $query_order, 20, 0, NULL, $values);
+  $combinations = array();
+  $i=1;
+  foreach ($attribute_ids as $aid){
+    $attribute_options = array();
+    $result = db_query("SELECT DISTINCT ao.aid AS aid, ao.name AS name, ao.oid AS oid, po.ordering FROM {uc_product_options} AS po LEFT JOIN {uc_attribute_options} AS ao ON po.oid = ao.oid WHERE po.nid = %d AND ao.aid = %d ORDER BY po.ordering ASC",$nid, $aid);
+    while ($a_o_combo = db_fetch_array($result)){ 
+      $attribute_options[] = array('aid' . $i => $a_o_combo['aid'], 'name' . $i => $a_o_combo['name'], 'oid' . $i => $a_o_combo['oid'], 'ordering' . $i => $a_o_combo['ordering']);
+    }
+    $i++;
+    //First time through, no combinations
+    if (empty($combinations)){
+      $combinations = $attribute_options;  
+    } else {
+      $bigger_combo= array();
+      foreach ($combinations as $existing_combo){
+        foreach ($attribute_options as $retrieved_combo){
+          $bigger_combo[] = array_merge($existing_combo, $retrieved_combo);
+        }
+      }
+      $combinations = $bigger_combo;
+    }
+    
+  }
+  
+    //Pass the combinations into a 'array pager' - this mimics the pager functions without pager_query
+    //The hardcoded 0 in this function call will cause issues if there's more than one pager on the page.. 
+    //but that was the previous behaviour
+    $combinations = _uc_attribute_array_pager($combinations, 20, 0, NULL);
 
     $form['original'] = array(
       '#value' => '<div><br /><b>'. t('Default product SKU: @sku', array('@sku' => $model)) .'</b></div>',
@@ -1100,14 +1111,14 @@
     );
 
     $i = 0;
-    while ($combo = db_fetch_object($result)) {
+    foreach ($combinations as $combo) {
       $cells = '';
       $row_title = '';
       $comb_array = array();
       for ($j = 1; $j <= $num_prod_attr; ++$j) {
-        $cells .= '<td>'. check_plain($combo->{'name'. $j}) .'</td>';
-        $row_title .= check_plain($combo->{'name'. $j}) .', ';
-        $comb_array[$combo->{'aid'. $j}] = $combo->{'oid'. $j};
+        $cells .= '<td>'. check_plain($combo['name'. $j]) .'</td>';
+        $row_title .= check_plain($combo['name'. $j]) .', ';
+        $comb_array[$combo['aid'. $j]] = $combo['oid'. $j];
       }
       ksort($comb_array);
       $row_title = substr($row_title, 0, strlen($row_title) - 2);
@@ -1161,6 +1172,23 @@
   return $form;
 }
 
+//"Borrowed" from pager.inc pager_query - this would be nice to have in drupal core for situations like these.
+function _uc_attribute_array_pager($paged_array, $limit = 10, $element = 0) {
+  global $pager_page_array, $pager_total, $pager_total_items;
+  $page = isset($_GET['page']) ? $_GET['page'] : '';
+
+  // Convert comma-separated $page to an array, used by other functions.
+  $pager_page_array = explode(',', $page);
+
+  // We calculate the total of pages as ceil(items / limit).
+  $pager_total_items[$element] = count($paged_array);
+  $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
+  $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
+  //return the proper slice of the array
+  return array_slice($paged_array, $pager_page_array[$element] * $limit, $limit, TRUE);
+  
+}
+
 /**
  * @see uc_product_adjustments_form()
  */
