i'm designing a page where i want to view entries sequentially by date added, grouped by month. i want to limit it to only the 3 most current months though. ideally, what the output should look like is this:
june
entry 1
entry 2
may
entry 1
entry 2
april
entry 1
entry 2
my only problem is this: i don't know how to code it to get each month region to repeat itself....here's my code:
$cur_month = date('m');
$cur_year = date('Y');
mysql_select_db($database_db, $db);
$query_thoughts = "select *, date_format(date, '%M') as month, date_format(date, '%m') as numMonth, date_format(date, '%m.%d.%Y') as fulldate from BBallThoughts ORDER BY date DESC";
$thoughts = mysql_query($query_thoughts, $db) or die(mysql_error());
$row_thoughts = mysql_fetch_assoc($thoughts);
$totalRows_thoughts = mysql_num_rows($thoughts);
<div id="thoughts">
<?php do { ?>
<h1><?php echo $row_thoughts['month']; ?></h1>
<?php do { ?>
<h2><?php echo $row_thoughts['title']; ?></h2>
<p><span class="rightdate"><?php echo $row_thoughts['fulldate'].' ::: '; ?></span><?php echo $row_thoughts['text']; ?></p>
<?php } while ($row_thoughts['numMonth'] == $cur_month); ?>
<?php $cur_month = $cur_month--; ?>
<?php } while ($row_thoughts = mysql_fetch_assoc($thoughts)); ?>
</div>
my thought was this: have php/mysql output the month name and all it's corresponding entries for that month, then decrease the month # by one and repeat. am i way off base here? should i be making multiple queries instead? especially since it'll always show 3 months at a whack?
thanks alot for the help