- $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE);
-
- $notice->find();
-
- common_element_start('div', 'notices');
-
- while ($notice->fetch()) {
- $this->show_notice($notice);
+
+ # We fetch one extra, to see if we need an "older" link
+
+ $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
+
+ $cnt = $notice->find();
+
+ if ($cnt > 0) {
+ common_element_start('ul', array('id' => 'notices'));
+ for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
+ if ($notice->fetch()) {
+ $this->show_notice($notice);
+ } else {
+ // shouldn't happen!
+ break;
+ }
+ }
+ common_element_end('ul');