different every day

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 12, 2011   (RSS)

By jtedescojam - January 12, 2011

Italian word of the day... my client has posted the word and it's meaning for about 10 words and want to post more... but we want them to rotate every day. We can start with the first record and display the second record tomorow, third the day after and so on (or even randomly display one per day, whichever is easier). Please assist with the code. here's what I have now which is set for displaying them at random.

Header Code
list($italian_word_of_the_dayRecords, $italian_word_of_the_dayMetaData) = getRecords(array(
'tableName' => 'italian_word_of_the_day',
'where' => whereRecordNumberInUrl(1),
'orderBy' => 'RAND()',
'limit' => '1'
));


Body Code

<?php foreach ($italian_word_of_the_dayRecords as $record): ?><p><strong class="italianWord"><?php echo $record['italian_word'] ?></strong><?php echo $record['english_word'] ?></p><?php endforeach ?>
John Tedesco

Creative Director



JAM Graphics

Re: [jtedescojam] different every day

By Jason - January 12, 2011

Hi,

There are a number of different ways to do this depending on the exact functionality you need.

One approach is to use the removeDate special field. What you do is go into your section editor for italian_word_of_the_day and add a date/time field and give it the name removeDate (NOTE the name must be exactly like that).

For each record, give the record a removeDate of the day AFTER you want it to appear.

So if you want the record to appear January 12, give it a remove date of January 13.

You would then select the record like this:

list($italian_word_of_the_dayRecords, $italian_word_of_the_dayMetaData) = getRecords(array(
'tableName' => 'italian_word_of_the_day',
'where' => whereRecordNumberInUrl(1),
'orderBy' => 'removeDate ASC',
'limit' => '1'
));


If you ever want a record to appear again, you can just go in and adjust it's removeDate. The one issue with this is that you do need to manage your records. If there is no record with a removeDate that's after the current date, no record will be selected.

Give this a try.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/