News archive
-
render($news);
?>
['default' => 1]]); } else{ $archive_page = 1; } $_SESSION['archive_page'] = $archive_page; $news_per_page = 10; try{ $sql = 'SELECT COUNT(*) as total FROM news'; $result = $pdo->query($sql); if($result->rowCount() > 0){ while($row = $result->fetch()){ $max_page = ceil($row['total']/$news_per_page); } // Free result set unset($result); } else{ unset($pdo); http_response_code(404); include('/en/404.html'); die(); } } catch(PDOException $e){ die('ERROR: Could not able to execute $sql. ' . $e->getMessage()); } $pages = array('pages' => array( 'first' => max(1, $archive_page-2), 'last' => min($max_page, $archive_page+2), 'current' => $archive_page, 'base_link' => '/en/news_archive.html?page=' )); $news = array('news' => array()); // Attempt select query execution try{ $sql = 'SELECT id, date, stub FROM news ORDER BY date DESC LIMIT ' . ($archive_page-1)*$news_per_page . ', ' . $news_per_page; $result = $pdo->query($sql); if($result->rowCount() > 0){ while($row = $result->fetch()){ $article_data = array( 'id' => $row['id'], 'date' => date('d.m.Y', strtotime($row['date'])), 'stub' => $row['stub'], 'link' => '/en/news.html?id=' . $row['id'] ); array_push($news['news'], $article_data); } // Free result set unset($result); } else{ unset($pdo); http_response_code(404); include('/en/404.html'); die(); } } catch(PDOException $e){ die('ERROR: Could not able to execute $sql. ' . $e->getMessage()); } #article template $article = $twig->load('article_news_archive_en.html'); $pagination = $twig->load('pagination_en.html'); ?>