Link to display records in last 7 days

2 posts by 2 authors in: Forums > CMS Builder
Last Post: December 5, 2008   (RSS)

By rjbathgate - December 4, 2008

Hi guys,

I'm looking to make a link to a list page which passes the criteria:

all records from said table where created date (i.e. date entered into database) is within the last X (7) days.

I already had the standard list page all set up - i just need to send the 'last 7 days' criteria through.

Is this possible?

Or do I need a new listing page, which is set to only display results from last 7 days by default, and simply link straight to that?

I already have code to display records on a list page where the date is within x days from today, so I can do the latter option, but the easier option would be the criteria in the url to the existing listing page (then I don't have to make a new listing page).

Many thanks in advance
Rob

Re: [rjbathgate] Link to display records in last 7 days

By Dave - December 5, 2008 - edited: March 1, 2010

Hi Rob,

You need a little custom PHP and MySQL for this:

Assuming your viewer url looks like this: yourViewer.php?days=7

You could get the days like this:

<?php
$days = (int) @$_REQUEST['days'];
if (!$days) { $days = 7; } // set default
$escapedDays = mysql_real_escape_string($days);
?>

And do a query like this:

'where' => "createdDate <= (NOW() - INTERVAL $escapedDays DAY) "

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com