Jump to content

Pulling Data from a file using a date range...


JohnnyBoy928

Recommended Posts

I have this simple news article program I have been working on... Works great for the most part but I have a question I keep stumbling on being fairly new at php...

 

This code below pulls articles from a summary data file (article_summary.html) and it includes the latest xx amount of articles I declare in the conf file... I need the conf file for other various items but I still want to keep the count of how many are displayed/pulled...

 

What I am having issues with is adding a date and more specifically a year... I would like to show xx amount of the latest articles from the year 2010 for instance... (i.e. The latest 100 articles from year 2010)... Right now this shows the latest 100 from current day to previous...

 

Thanks in advance for any help...

 

main code that calls articles (I need to add date/year filter somehow)

<?

        require('config.php'); 

$filename = "article_summary.html";

#- open article summaries
if(file_exists($filename)){
	$fh = fopen($filename, "r");
	$old_news = fread($fh, filesize($filename));
	fclose($fh);
}


#- get first five article
$articles = explode("<!--ARTICLE-->", $old_news);

$i=0;
foreach ( $articles as $article ){
	if(count($articles)>$i){
		if($max_latest >= $i++){
			print $article;
		}
	}
}

?>

 

config.php

<?

$summary_template = "t_summary.html";

$article_template = "t_article.html";

$max_summary = 100;

$max_latest = 100; $password = "xxxxx";

?>

 

This code is from the article_summary.html and the date is in the filename of the link... This is where I keep having sytax issue with my coding...

<!--ARTICLE-->
<b><a href=http://www.mydomain.com/articles/gaming/article_GAMING_2010_08_1_4459.html>Proposed Merger of PartyGaming and bwin Interactive Entertainment </a></b><br />
<div align="justify">Creation of the world’s largest listed online gaming business</div>

<!--ARTICLE-->
<b><a href=http://www.mydomain.com/articles/gaming/article_GAMING_2010_05_21_4723.html>Lawmakers consider Internet gambling bills</a></b><br />
<div align="justify">Internet gambling should be legalized and taxed in the United States to raise  billion in revenue over a decade and legitimize gamers who bet online, </div>

<!--ARTICLE-->
<b><a href=http://www.mydomain.com/articles/gaming/article_GAMING_2010_03_16_3434.html>Las Vegas, Nevada is preparing for legal online casino gambling within the United States.</a></b><br />
<div align="justify">Known as the capital of land-based gambling in the US, they want to get a fresh start with online gambling once it becomes legal on a federal level. </div> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.