Filtering search results by date created range.

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

By gkornbluth - November 25, 2013 - edited: November 25, 2013



Hi All,
I’ve created a search form that filters results and displays them on a separate list page using the _match, _max and _min functions.

I’m stuck on how to filter the results to show only those records created in the last month, or the last 2 months, or the last 3 months, or more than 3 months old, in addition to any other filters imposed.

Here’s an example of the code I’m using. The last row in the table is the one I’m stuck on.

 <table width="40%" border="0" cellspacing="0" cellpadding="2">
<form method="POST" class="arial_14" action="listings.php">
      <tr>
        <td class="arial_14"><font color="#FFFFFF"><b>Price: </b></font> </td>
        <td><select name = "price_min"  width="135" class="arial_14" style="width: 135px">
            <option value="">Minimum</option>
            <option value="">Any</option>
            <option value="">$0</option>
            <option>$  500</option>
            <option>$1,000</option>
            <option>$1,500</option>
            <option>$2,000</option>
          </select></td>
        
       <td>&nbsp; &nbsp; &nbsp;</td>
        <td><select name = "price_max" width="135" class="arial_14" style="width: 135px">
            <option value="">Maximum</option>
            <option value="">Unlimited</option>
            <option>$  500</option>
            <option>$1,000</option>
            <option>$1,500</option>
            <option>$2,000</option>
           </select></td>
      </tr>
     <tr>
        <td class="arial_14"><font color="#FFFFFF"><b>Breed: </b></font></td>
        <td colspan="3"><select name = "dog_breed_match" width="300" class="arial_14" style="width: 300px">
            <option value="">Please Choose a Breed</option>
            <?php foreach (getListOptions('lm_listing', 'dog_breed') as $value => $label2): ?>
            <option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['dog_breed']);?>> <?php echo $label2; ?></option>
            <?php endforeach ?>
          </select></td>
      </tr>
       
<tr>
 <td class="arial_14"><font color="#FFFFFF"><b>Date Listed: </b></font></td>
  <td colspan="3"><select name="age" width="300" class="arial_14" style="width: 300px">
            <option value="">All Dates</option>
            <option value="a">Listed less than 1 Month ago</option>
            <option value="b">Listed less than 2 Months ago</option>
            <option value="c">Listed less than 3 Months ago</option>
            <option value="d">Listed more than 3 Months ago</option>
          </select></td>
      </tr>  
      <tr>
      <td class="arial_14"><b>&nbsp;</b> </td>
        <td align="left" colspan="3"><input type="submit" name="submit" value="Search" ></td>
      </tr>
     </form>
      <FORM ACTION="" "class=arial_14">
      <tr>
      <td class="arial_14"><b>&nbsp;</b> </td>
        <td align="left" colspan="3"><INPUT TYPE="submit" VALUE="Cancel Search Filters"></td>
      </tr>
      </FORM>
    </table>
   

Has anybody done this type of thing before that’s willing to share their knowledge?

Thanks

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 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

By gkornbluth - November 28, 2013

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