From fa8180ea3a41584943dd7464eb8c3cad769d8211 Mon Sep 17 00:00:00 2001 From: jhunkeler Date: Sun, 17 Apr 2011 16:49:09 +0000 Subject: Jessus christ git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2.1@491 c5b2fb0a-d05d-0410-98c8-828840a80ff6 --- modules/news/functions.php | 19 +++++++++++++------ modules/news/index.php | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 7 deletions(-) (limited to 'modules/news') diff --git a/modules/news/functions.php b/modules/news/functions.php index 22952af..f3505df 100644 --- a/modules/news/functions.php +++ b/modules/news/functions.php @@ -127,7 +127,7 @@ function getNumOfComments($id){ * Function that gets the desired news from the database and returns it as an array * @param id - (optional) news_id cooresponding to `bayonet_news` */ -function getNews($id = NULL){ +function getNews($id = NULL, $limit = NULL, $index = 0){ global $db; $query = "SELECT n.news_id, n.title, n.message, n.date, n.category_id, u.username AS author, c.name AS catname, c.image AS catimage ". @@ -138,11 +138,12 @@ function getNews($id = NULL){ $query = $query."WHERE n.news_id = '$id' "; }else{ $query = $query."ORDER BY date DESC"; - if($limit !=NULL){ - $query = $query." LIMIT '$limit'"; - } + if($index > 0) + $query = $query." LIMIT $index, $limit"; + else if($limit !=NULL) + $query = $query." LIMIT $limit"; } - + decho($query); $result = $db->Query($query); $data = $db->Fetch($result); @@ -159,6 +160,12 @@ function displayNews($data){ date_default_timezone_set("America/New_York"); + if(empty($data)){ + ReportError("Sorry, we found no news using these parameters."); + echo "
"; + } + + foreach($data as $news) { $numComments = getNumOfComments($news['news_id']); @@ -235,7 +242,7 @@ function commentForm(){ echo "Guest"; } ?> -

+

diff --git a/modules/news/index.php b/modules/news/index.php index 6aaec2d..1dfd98a 100644 --- a/modules/news/index.php +++ b/modules/news/index.php @@ -27,6 +27,20 @@ include 'modules/news/functions.php'; $logged_id = 2; +if(!defined('INDEX_MODULE')){ + $page_num = 1; + $page_num = $_GET['page']; //get variable for page number + + $page_num --; //so the $index can be calculated easier while keeping [1,n] page numbers + + $limit = 3; //number of items per page + $index = $page_num * $limit; + +}else{ + //only do the limit + $limit = 3; +} + if(isset($_GET['id'])) { $news_id = $_GET['id']; @@ -36,9 +50,35 @@ if(isset($_GET['id'])) } else { - displayNews(getNews()); + $news = getNews(null, $limit, $index); + displayNews($news); + OpenContent(); + if(defined('INDEX_MODULE')){ +?> +
+ Read All  +
+ + 0) + echo " More Recent News"; + + decho("count: ".count($news)); + if(count($news) == $limit){ +?> +
+ Older News  +
+"; + CloseContent(); return; } + + ?> \ No newline at end of file -- cgit