Filtering search results by date created range.

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

By Dave - November 28, 2013

Hi Jerry, 

Try this:

<select name="age_min" width="300" class="arial_14" style="width: 300px">
  <option value="">All Dates</option>
  <option value="<?php echo mysql_datetime(strtotime("-1 month")); ?>">Listed less than 1 Month ago</option>
  <option value="<?php echo mysql_datetime(strtotime("-2 month")); ?>">Listed less than 2 Months ago</option>
  <option value="<?php echo mysql_datetime(strtotime("-3 month")); ?>">Listed less than 3 Months ago</option>
</select>

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com

Thank you Captain,

I'm in the middle of our Turkey devouring ritual, but I'll jump on it first thing in the morning.

You folks are the best!

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - January 3, 2014 - edited: January 3, 2014

Sorry that it took so long to post, but here's the code that finally worked:

On the search page (search.php)

<table width="40%" border="0" cellspacing="0" cellpadding="2">
    <form method="POST" class="your_class" action="listings-s.php">
  <tr>
        <td class="arial_14"><font color="#FFFFFF"><b>Date Listed: </b></font></td>
        <td colspan="3">
            <select name="months_ago" width="300" class="your_class" style="width: 300px">
  <option value="">All Dates</option>
  <option value="1">Listed less than 1 Month ago</option>
  <option value="2">Listed less than 2 Months ago</option>
  <option value="3">Listed less than 3 Months ago</option>
</select>
</td>
 </tr>  
<tr>
<td class="your_class"><b>&nbsp;</b> </td>
<td align="left" colspan="3"><input type="submit" name="submit" value="Search" ></td>
</tr>
</form>
</table>


And on the results page (listings-s.php)

<?php
if (@$_REQUEST['months_ago']) {
  $monthsAgo = $_REQUEST['months_ago'];
  $_REQUEST['createdDate_min'] = mysql_datetime(strtotime("-$monthsAgo month"));
}
 ?>

<?php
  $searchCriteria = '';
  if (@$_REQUEST['months_ago']) { $searchCriteria .= "Listed Less Than: {$_REQUEST['months_ago']} months ago - "; }
  $searchCriteria = chop($searchCriteria, ', '); // remove trailing , or spaces
    $searchCriteria = chop($searchCriteria, '- '); // remove trailing - or spaces
  ?>

<div align="center"> <span class="your_class"> There are <?php echo $listingMetaData['totalRecords']; ?> listings that match your search for:
 <?php if ( @!$searchCriteria ):?>
 All Listings
 <?php else :?>
 <br />
 <?php echo $searchCriteria ?>
 <?php endif ?>
</span>
              
 <a href="search.php"><span class="your_class"><br />
 &lt;&lt; <u>Return to the Advanced Search Page</u></span></a></div>

Hope that helps someone.

Jerry Kornbluth
 

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php