I am using jetbox cms and trying to edit the code for a news section. Basically I have one page that shows just headlines with a menu that allows you to get a list of headlines by year. So If I want to get all the 2007 headlines the url would be ...view/news?whichNews=all&whichYear=2007
Right now in the database I only have one news item for 2006 and one for 2007 for testing purposes. So, when all the news is showing for all the years it only shows two total. However, when only 2007 news items are showing(which is only 1) it still shows 2 results, the same news story twice.
I tried to subtract from the number of rows but that doesn't seem to be the problem. Here is my code below, can anyone help me figure this out?
<?
// CONFIGURATION
// Container ID
// After you have created the administration container in Jetbox check the container ID in the overview list
$container_id=44;
$whichNews = $_GET["whichNews"];
$whichYear = $_GET["whichYear"];
if(!is_numeric($container_id)){
echo "Set the \$container_id to the appropriate value";
exit;
}
addbstack('', 'news', $view);
addbstack('', 'Home');
$t->set_file("block", "main_tpl.html");
$t->set_var("breadcrum", $breadcrumstack);
$t->set_var("itemtitle", "news");
$t->set_var("pagetitle", $sitename." - news");
//output news for selected item
$date=date("Y-m-d");
if($option=='last10'){
$sqlselect1 = "SELECT *, struct.id AS struct_id FROM news, struct WHERE struct.container_id=".$container_id." ".$wfqadd." AND struct.content_id=news.news_id ORDER BY news.news_id DESC LIMIT 10";
}
else{
$sqlselect1 = "SELECT *, struct.id AS struct_id FROM news, struct WHERE struct.container_id=".$container_id." ".$wfqadd." AND struct.content_id=news.news_id ORDER BY news.news_id DESC ";
}
$result1 = mysql_prefix_query ($sqlselect1) or die (mysql_error());
$newscount= mysql_num_rows($result1);
if ($newscount>'0') {
$view_tpl = new Template("./");
$view_tpl->set_file("block", "news_item_tpl.html");
$view_tpl->set_block("block", "news","newsz");
$view_tpl->set_var(array("absolutepathfull"=>$absolutepathfull ));
while ($resultarray = mysql_fetch_array($result1)){
if($resultarray["keywords"]<>''){
$t->set_var("pagekeywords", $resultarray["keywords"]);
}
if($resultarray["description"]<>''){
$t->set_var("pagedescription", $resultarray["description"]);
}
if($resultarray["robot"]<>''){
$t->set_var("robots", $resultarray["robot"]);
}
//$year = substr($resultarray["news_date"], 0, 4);
if($whichNews ==all && $whichYear ==all){
$view_tpl->set_var("news_id", $resultarray["news_id"]);
$view_tpl->set_var("news_title", $resultarray["news_title"]);
$view_tpl->set_var("news_date", $resultarray["news_date"]);
$view_tpl->set_var("news_img", $resultarray["news_img"]);
//$view_tpl->set_var("news_story", $resultarray["news_story"]);
}else if($resultarray["news_id"] == $whichNews && $whichYear == 0)
{
$view_tpl->set_var("news_id", $resultarray["news_id"]);
$view_tpl->set_var("news_title", $resultarray["news_title"]);
//$view_tpl->set_var("news_date", $resultarray["news_date"]);
$view_tpl->set_var("news_img", $resultarray["news_img"]);
$view_tpl->set_var("news_story", $resultarray["news_story"]);
$view_tpl->set_var("news_link", $resultarray["news_story"]);
}else if($year != all)
{
if(substr($resultarray["news_date"], 0, 4) == $whichYear)
{
$view_tpl->set_var("news_id", $resultarray["news_id"]);
$view_tpl->set_var("news_title", $resultarray["news_title"]);
$view_tpl->set_var("news_date", $resultarray["news_date"]);
$view_tpl->set_var("news_img", $resultarray["news_img"]);
echo $resultarray["news_title"];
//$view_tpl->set_var("news_story", $resultarray["news_story"]);
}
}
// ADD THIS BLOCK OPTION TO ONLY SHOW THE BLOCK WHEN THE FIELD IS FILLED
// $view_tpl->set_block("news", "NEWS_STORY","NEWS_STORYZ");
//if ($resultarray["news_story"]<>'') {
// $view_tpl->parse("NEWS_STORYZ", "NEWS_STORY");
//}
//else{
// $view_tpl->set_var("NEWS_STORYZ", "");
//}
$view_tpl->parse("newsz", "news", true);
}
$view_tpl->parse("b", "block");
$t->set_var("containera", $view_tpl->get("b"));
}
else {
$t->set_var("containera", "No news found.");
}
$navt = new Template("./");
$navt->set_file("block", "optionnav.html");
$navt->set_block("block", "sub","subz");
$navt->set_block("block", "subsel","subselz");
$navarray=array("all"=>array("url"=>$absolutepathfull."view/".$view."/","lname"=>"All"),
"past"=>array("url"=>$absolutepathfull."view/".$view."/option/last10","lname"=>"Last 10"),
);
if ($option) {
while (list($key, $val)= each($navarray)) {
$navt->set_var(array ("lname"=> $val["lname"],"url"=>$val["url"]));
if ($key==$option) {
$navt->parse("subz", "subsel", true);
}
else{
$navt->parse("subz", "sub", true);
}
}
}
else{
while (list($key, $val)= each($navarray)) {
$navt->set_var(array ("lname"=> $val["lname"],"url"=>$val["url"]));
if ($key=="all" && $item=='') {
$navt->parse("subz", "subsel", true);
}
else{
$navt->parse("subz", "sub", true);
}
}
}
$navt->set_var(array ("options"=> "Selection"));
$navt->parse("b", "block");
$t->set_var("leftnav", $navt->get("b"));
?>