Archives

4 posts by 2 authors in: Forums > CMS Builder
Last Post: August 24, 2009   (RSS)

Re: [apdance9] Archives

By Chris - August 21, 2009

Hi apdance,

Let's assume that you have two sections, named Issues and Articles. Both sections have a date/time field called "date", and for aesthetics, have the Specify Time option disabled.

On your Issue detail page, you'd want to pull the year and month out of the selected Issue record and use that information in a WHERE clause to find only Articles which match the year and month, like so:

list($issuesRecords, $issuesMetaData) = getRecords(array(
'tableName' => 'issues',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$issuesRecord = @$issuesRecords[0]; // get first record

// get year and month from selected Issue
$year = date('Y', strtotime( $issuesRecord['date'] ) );
$month = date('n', strtotime( $issuesRecord['date'] ) );

// search for articles matching that year and month
list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => "YEAR(date)={$year} AND MONTH(date)=${month}",
));


I've attached a complete Issue details page for reference.

Hope this helps! :D
All the best,
Chris
Attachments:

issuesdetail.php 3K

Re: [chris] Archives

By design9 - August 24, 2009

Hi Chris,

That worked perfectly! Thank you so much!

The last I need to do with this is have a current issue page that will display the current issue cover, title and links of articles for that month. Is there anyway to program this so it can automatically change each month (as each month changes) or would I need to manually change it. I was thinking I could set-up a checkbox that says "current month" and use a php if statement but then the user would have to go back each month and uncheck the expired month. Trying to figure out an easier way to accomplish this... I know I am missing something. Any suggestions would be appreciated!

Thanks!

April

Re: [apdance9] Archives

By Chris - August 24, 2009

Hi April,

(1) The simplest solution would rely on Issues being created as they become current. If this is the case, you can select the newest issue sorted by date:

list($issuesRecords, $issuesMetaData) = getRecords(array(
'tableName' => 'issues',
'orderBy' => 'date DESC',
'limit' => '1',
));
$issuesRecord = @$issuesRecords[0]; // get first record


This assumes that you'll be creating Issues as they become current and not ahead of time.

(2) Alternately, you could select the Issue matching today's month and year, but you'd want to be careful about the user forgetting to add Issues before they're ready to go live!

// find Issue matching today's MONTH and YEAR
list($issuesRecords, $issuesMetaData) = getRecords(array(
'tableName' => 'issues',
'where' => 'YEAR(date)=YEAR(NOW()) AND MONTH(date)=MONTH(NOW())',
'limit' => '1',
));
$issuesRecord = @$issuesRecords[0]; // get first record

// if no Issue exists for this month, find the latest one!
if (!$issuesRecord) {
list($issuesRecords, $issuesMetaData) = getRecords(array(
'tableName' => 'issues',
'where' => 'date < NOW()',
'orderBy' => 'date DESC',
'limit' => '1',
));
$issuesRecord = @$issuesRecords[0]; // get first record
}


Hope this helps! :)
All the best,
Chris