Index: trunk/core/kernel/db/db_tag_processor.php =================================================================== diff -u -r4945 -r4947 --- trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 4945) +++ trunk/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 4947) @@ -302,7 +302,7 @@ if ($columns>1 && $direction=="V") { $list->Records = $this->LinearToVertical($list->Records, $columns, $list->GetPerPage()); $list->SelectedCount=count($list->Records); - ksort($list->Records); + ksort($list->Records); // this is issued twice, maybe need to be removed } $list->GoFirst(); @@ -331,11 +331,14 @@ $this->Application->SetVar( $this->Prefix.'_id', $list->GetDBField($id_field) ); if ($i % $columns == 0) { + // record in this iteration is first in row, then open row $column_number = 1; $o.= $block_start_row_params['name'] ? $this->Application->ParseBlock($block_start_row_params, 1) : ''; } if (!$list->getCurrentRecord()){ + // doesn't add empty cell, by the fact it should add that much empty cells, + // how much elements are missing in last row, but not on cell as for now $o.= $block_empty_cell_params['name'] ? $this->Application->ParseBlock($block_empty_cell_params, 1) : ' '; } else { @@ -346,6 +349,7 @@ } if (($i+1) % $columns == 0) { + // record in next iteration is first in row too, then close this row $o.= $block_end_row_params['name'] ? $this->Application->ParseBlock($block_end_row_params, 1) : ''; } @@ -1309,11 +1313,18 @@ function LinearToVertical(&$arr, $columns, $per_page) { $rows = $columns; + // in case if after applying per_page limit record count less then + // can fill requrested column count, then fill as much as we can $cols = min(ceil($per_page / $columns), ceil(count($arr) / $columns)); $imatrix = array(); for ($row = 0; $row < $rows; $row++) { for ($col = 0; $col < $cols; $col++) { - $imatrix[$col * $rows + $row] = $arr[$row * $cols + $col]; + $source_index = $row * $cols + $col; + if (!isset($arr[$source_index])) { + // in case if source array element count is less then element count in one row + continue; + } + $imatrix[$col * $rows + $row] = $arr[$source_index]; } }