68 Classifieds Forums
Go Back   68 Classifieds Forums > v3.1.x Help & Support > v3.1 Modifications > Adding date search to search.php
v3.1 Modifications Questions on modifying 68 Classifieds. Please note these are not supported by 68 Classifieds, and may make future updates more difficult.

 
Thread Tools Display Modes
(#1)
Old
abkeller abkeller is offline
Junior Member
abkeller is on a distinguished road
 
Posts: 19
Join Date: May 2007
Location: Gilroy, CA
Default Adding date search to search.php - 06-04-2007, 06:08 PM

I need to add a drop-down menu to the search.php function that I have not been able to create using the "Add Extra Fields" option. This would be a dynamic search field which does a comparison between current date/time and the "dateadded" timestamp that is added to every new listing at the time of posting. The logic goes like this;

Search by;

Anytime = no restrictions (search all)
Last 24 hours = range = (currentdate/time) to (all dateadded equaling currentdate/time minus 24 hours)

Last 3 Days = range = (currentdate/time) to (all dateadded equaling currentdate/time-72 hours)

Last Week = range = (currentdate/time) to (all dateadded equaling currentdate/time-7days)

Last Month = range = (currentdate/time) to (all dateadded equaling currentdate/time-30 days)

The "Search Settings" option in the admin control panel only allows me to sort by dateadded, but I want users to search by dateadded using the above logic.

Can anyone help with this?

Thanks much!


Elizabeth
www.gunmountain.com
68Classifieds - Developer Edition, v.3.1.7
Reply With Quote
(#2)
Old
midi510 midi510 is offline
Senior Member
midi510 is a jewel in the rough
 
Posts: 134
Join Date: Mar 2007
Location: Mammoth Lakes, Ca
Default 06-05-2007, 12:33 AM

You might look into toplistings.php. The link for new listings in the default navigation section is toplistings.php?pg=new, which is basically a search by listing date/time. You could do something like "Recent ads: 24hr 3day Week Month". Each link would call toplistings.php?pg=xxx. Look at the switch code on line 61. You should be able to create some new cases with more specific parameters. (Theoretically anyway.)


Kirk
V3.1.7 Developer
May you & your loved ones be blessed with
Grace, Peace, Forgiveness, Love, Wisdom, & Joy
Reply With Quote
(#3)
Old
abkeller abkeller is offline
Junior Member
abkeller is on a distinguished road
 
Posts: 19
Join Date: May 2007
Location: Gilroy, CA
Default Figured this one out, too.... - 06-29-2007, 02:40 AM

In order to incorporate the date search function on my search.php page I grabbed the code from the admin control panel where you can search your listings. One of the search features is by date, using either javascript pop-up calendars you can use to select a date range, or by clicking on the text links with preconfigured time frames; Lat month, last week, last 24 hours, and Today.

First, I grabbed the php code that runs the date search from the admin file called browselistings.php to make sure the search query could handle the data ranges;

//now get the search fields
if (isset($_REQUEST['fromdate']) && $_REQUEST['fromdate']<>"")
{
$enddate=date("Y-m-d");
if(isset($_REQUEST['enddate']) && $_REQUEST['enddate']<>"")
{
$enddate=$_REQUEST['enddate'];
}
$sSQL .= " AND p.dateadded BETWEEN '".trim($_REQUEST['fromdate'])."' AND '".trim($enddate)." 23:59:59'";
}
else
{
$today=date("Y-m-d");
$sSQL .= " AND p.dateadded BETWEEN '".$today." 00:00:00' AND '".$today." 23:59:59'";
}
if(isset($_REQUEST['active']) && $_REQUEST['active']=="N")
{
$sSQL .= " AND p.display<>'Y'";
}
elseif(isset($_REQUEST['active']) && $_REQUEST['active']=="Y")
{
$sSQL .= " AND p.display='Y'";
}

if(isset($_GET['orderby']) && isset($_GET['sortby']))
{
$orderby=$_GET['orderby'] .' '. $_GET['sortby'];
}
else
{
$orderby='dateadded DESC';
}
$sSQL .= " ORDER BY ". $orderby;

//now display the template
$today=date("Y-m-d");
$month = mktime(0,0,0,date("m")-1,date("d"),date("Y"));
$month = strftime("%Y-%m-%d",$month);
$week = mktime(0,0,0,date("m"),date("d")-7,date("Y"));
$week = strftime("%Y-%m-%d",$week);
$day = mktime(0,0,0,date("m"),date("d")-1,date("Y"));
$day = strftime("%Y-%m-%d",$day);
$class_tpl->assign('month', $month);
$class_tpl->assign('week', $week);
$class_tpl->assign('day', $day);
$class_tpl->assign('today', $today);
$class_tpl->assign('fromdate', @$_REQUEST['fromdate']);
$class_tpl->assign('enddate', @$enddate);
$class_tpl->assign('max', $max);
$class_tpl->assign('page', $currentPage);
$class_tpl->assign('first', $first);
$class_tpl->assign('prev', $prev);
$class_tpl->assign('next', $next);
$class_tpl->assign('last', $last);
$class_tpl->assign('pageNum', $pageNum);
$class_tpl->assign('pageNumber', $pageNumber);
$class_tpl->assign('maxPage', $maxPage);

if($numrows==0)
{
$class_tpl->assign('noresults', LANG_ADMIN_NO_RESULTS);
}
else
{
$class_tpl->assign('results', $results);
}

$class_tpl->assign('searchquery', $queryString_search);
$class_tpl->assign('totalPrice', $totPrice);

$class_tpl->display('layout.tpl.php');

Copied the above code into the search.php file.

Then I changed the text link options into a drop-down menu and added it to the search.tpl.php page like this;

<td valign="top" class="formleft"><div align="right">New Listings
added </div></td>
<td valign="top" class="formright"><select name="select">
<option selected>Antyime</option>
<option value="fromdate={$today}&enddate={$today}">Tod ay</option>
<option value="fromdate={$day}&enddate={$today}">Since Yesterday</option>
<option value="fromdate={$week}&enddate={$today}">In the Last
Week</option>
<option value="fromdate={$month}&enddate={$today}">In the
Last Month</option>
</select>   </td>


Works great!


Elizabeth
www.gunmountain.com
68Classifieds - Developer Edition, v.3.1.7
Reply With Quote
(#4)
Old
midi510 midi510 is offline
Senior Member
midi510 is a jewel in the rough
 
Posts: 134
Join Date: Mar 2007
Location: Mammoth Lakes, Ca
Default 06-30-2007, 11:55 AM

I did some searches on your site and came up with results outside of the time frame I specified. For instance I selected "last 24 hours" and put in "44 Magnum" and got ads from over a week ago. Also, I just selected "today" with no keyword and got five pages worth of ads from before today. Sorry to rain on your parade, but are you sure it's working right.


Kirk
V3.1.7 Developer
May you & your loved ones be blessed with
Grace, Peace, Forgiveness, Love, Wisdom, & Joy

Last edited by midi510 : 06-30-2007 at 11:59 AM.
Reply With Quote
(#5)
Old
abkeller abkeller is offline
Junior Member
abkeller is on a distinguished road
 
Posts: 19
Join Date: May 2007
Location: Gilroy, CA
Default Date search NOT working - 07-03-2007, 01:31 AM

You're right, Kirk. When I do the search my query string is all screwed up, with odd characters in it like this;


"...select=fromdate%3D2007-07-02%26enddate%3D2007-07-02..."

It looks like enclosing the date parameters in quotes inside of an option/select form tag converts the { and } to unreadable characters.

Any ideas on how to properly format the syntax for this date search in a drop-down menu so that this doesn't happen?


Elizabeth
www.gunmountain.com
68Classifieds - Developer Edition, v.3.1.7

Last edited by abkeller : 07-03-2007 at 01:31 AM. Reason: misspelling
Reply With Quote
(#6)
Old
midi510 midi510 is offline
Senior Member
midi510 is a jewel in the rough
 
Posts: 134
Join Date: Mar 2007
Location: Mammoth Lakes, Ca
Default 07-03-2007, 10:28 AM

I'd like to spend some time on this, but I just have too many other things going on. I'll let you know if I do get any results.


Kirk
V3.1.7 Developer
May you & your loved ones be blessed with
Grace, Peace, Forgiveness, Love, Wisdom, & Joy
Reply With Quote


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding extra field to search.php... abkeller v3.1 Modifications 4 06-05-2007 12:15 AM
Search members by join date not working zman78 v3.1 Questions & Support 8 07-30-2006 12:33 PM
Adding Short Description To Search Results CB v3.1 Questions & Support 5 06-22-2006 04:52 PM
Adding the Owner Name to the search results robgo777 v3.1 Questions & Support 6 06-13-2006 10:21 AM
Adding Search to sleepy Template Design Questions 8 04-09-2006 12:12 PM



Powered by vBulletin® Version 3.6.3
Copyright ©2000 - 2007, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com