I have a page that queries MySQL and gets all news articles and then will auto generate a page that will show recent articles and then pr the previous month back i need it to place relevant articles in the respective months, like an archive.
ex:
recent articles
article 50
article 49
may 2006
article 48
article 47
etc..
I use another function to get recent articles so this function i am about to show starts at -1 for months. My for loop is not doing what i want it to. basically it only displays the last month and will not output more than one month back.
Code: Select all
function article_toc(){
$cur_year = date('Y');
$cur_month = date('m');
$cur_day = date('d');
$pattern = '/^(\d{1,4})-(\d{1,2})-(\d{1,2})\s(\d*):(\d{2}):(\d{2})$/';
$content = '<div class="catalog_page_content_row"><p class="accessory_details">';
//get information from database
$sql = "SELECT title, link, date_created FROM blog";
$rs= mysql_query($sql) or die("Error on Line 198: ".mysql_error());
// date("F")-1 does not work so we create an array and use date("m")-1 to get value from array to display current month
$months = array(01=>'January', 02=>'February', 03=>'March', 04=>'April', 05=>'May', 06=>'June', 07=>'July', 08=>'August', 09=>'September', 10=>'October', 11=>'November', 12=>'December');
for($m=1;$m<=12; $m++){
$past = date("m") - $m;
while($article_rs = mysql_fetch_assoc($rs)){
// get the month from database timestamp
$article_month = preg_replace($pattern,'$2' , $article_rs['date_created']);
if($article_month == $past){
$past = $months[$past];
$content .= '<span class="cart_item_ul2"><b>'.$past.' '.date('Y').'</b></span><br />';
//$content .= '<span class="cart_item_ul2"><b>Current Articles</b></span><br />';
$content .= '<a href ="'.$article_rs['link'].'">'.$article_rs['title'].'</a><br />'. $m;
} // if
} // while
} // for
$content .= '</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>';
echo $content;
}//functionAny help would be great!!!!