Displaying new listings only

5 posts by 2 authors in: Forums > CMS Builder
Last Post: May 17, 2011   (RSS)

Re: [andybarn] Displaying new listings only

By Jason - May 9, 2011

Hi Andy,

You can link to a separate page and use a query that only returns records created/modified in the last thirty days. You can try something like this:


$thirtyDaysAgo = date("Y-m-d", strtotime("-30 days", strtotime(date("Y-m-d"))));

list($recentListingsRecords, $recentListingsMetaData) = getRecords(array(
'tableName' => 'listings',
'allowSearch' => false,
'where' => "createdDate >= '$thirtyDaysAgo' OR updatedDate >= '$thirtyDaysAgo'",
));


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Displaying new listings only

By andybarn - May 15, 2011

Hi Jason

Thanks for your help.

I am not sure where the code you supplied should go. I have created a page called listings_date.php and have put the code at the top just after the "STEP 1: LOAD RECORDS..." code as follows:-

<?php

require_once "init.php";

list($listingRecords, $listingDetails) = getRecords(array(
'tableName' => 'listings',
'joinTable' => 'homepages',
'perPage' => '10',

));

$thirtyDaysAgo = date("Y-m-d", strtotime("-1 days", strtotime(date("Y-m-d"))));

list($recentListingsRecords, $recentListingsMetaData) = getRecords(array(
'tableName' => 'listings',
'allowSearch' => false,
'where' => "createdDate >= '$thirtyDaysAgo' OR updatedDate >= '$thirtyDaysAgo'",
));

?>
<?php include "include_header.php"; ?>


Is this correct? (the only change I made was that I change the -30 to -1 to show changes in the last day. When I display this page it still shows all the records.

Hope you can point me in the right direction.

Thanks again for your help.

Andy

Re: [andybarn] Displaying new listings only

By Jason - May 16, 2011

Hi Andy,

Yes, changing "-30 days" to "-1 days" changes the code so that it's only showing records created or updated within the last day.

In the code you posted, you're executing 2 queries: 1 that returns all records (10 per page) to a variables called $listingRecords, and 1 that returns all records created or updated within the last day to a variable called $recentListingsRecords.

If you want to only show the listings created or updated in the last day, make sure that you use $recentListingsRecords in your foreach loop.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Displaying new listings only

By andybarn - May 17, 2011

Hi Jason

Brilliant!

That was it, once I used $recentListingsRecords in my foreach loop , my page worked as I wanted - perfect!

Thanks for your great support

Andy