I’m currently trying to make a news archive list and feel I almost have it right, but could use some help in finishing it off.
Currently my archive looks like this: (See Attachment Current_Archive.jpg) Notice I’m only getting one result per month.
I want it to look like this: (See Attachment Archive_Needed.jpg) Notice here I’m getting more than one result per month. This is just a Photoshop example. I dont want the same file names just more results under each month.
Here is the code I’m working with.
[php]<?php
include($_SERVER[‘DOCUMENT_ROOT’] . “/includes/database.php”);
$stmt = $db->prepare(“SELECT id
,date
,title
FROM htp_news
ORDER BY date DESC”);
if ($stmt->execute()) {
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
$current_year = date(“Y”, strtotime($row[1]));
$current_month = date(“F”, strtotime($row[1]));
if ($current_year > $last_year) {
echo "<h1>" . $current_year . "</h1>";
echo "<h2>" . $current_month . "</h2>";
$last_year = $current_year;
$last_month = $current_month;
echo “
- ”;
- ” . date(“M d, Y”, strtotime($row[1])) . " - " . $row[2] . “ ”;
echo “
echo “
}
elseif ($current_month > $last_month) {
echo “
” . $current_month . “
”;$last_month = $current_month;
echo “
- ”;
- ” . date(“M d, Y”, strtotime($row[1])) . " - " . $row[2] . “ ”;
echo “
echo “
}
elseif ($current_year < $last_year) {
echo “
” . $current_year . “
”;echo “
” . $current_month . “
”;$last_year = $current_year;
$last_month = $current_month;
echo “
- ”;
- ” . date(“M d, Y”, strtotime($row[1])) . " - " . $row[2] . “ ”;
echo “
echo “
}
elseif ($current_month < $last_month) {
echo “
” . $current_month . “
”;$last_month = $current_month;
echo “
- ”;
- ” . date(“M d, Y”, strtotime($row[1])) . " - " . $row[2] . “ ”;
echo “
echo “
}
}
}
?>[/php]
Any help would be greatly appreciated!