Date Manipulation and search

L

Lincoln

Guest
Hello!
I am trying to create a feature where the user can view all records with a date greater than one month ago. I have a script that calculates this date relative to todays date. Here it is:

<?php
// get the current timestamp into an array
$timestamp = time();
$date_time_array = getdate($timestamp);

$hours = $date_time_array['hours'];
$minutes = $date_time_array['minutes'];
$seconds = $date_time_array['seconds'];
$month = $date_time_array['mon'];
$day = $date_time_array['mday'];
$year = $date_time_array['year'];

// use mktime to recreate the unix timestamp
// subtract one month
$timestamp = mktime($hours,$minutes,$seconds,$month - 1,$day,$year);
$lastmonth = strftime('%Y %m %d',$timestamp);



?>

I would like to execute this search like this:
http://www.mysite.com/mydir/index.php?function=search&where_clause=Date>"$lastmonth"&page=0&table_name=mytable

I have the concept pretty clear but i'm not quite sure how to implement it.

Any help would be greatly appreciated.

Thank You! -lincoln
 
L

Lincoln

Guest
Ok, i figured it out.

My line numbers are different so if your interested in this just insert it in index.php after the the section...

///////////////from index.php v3.1 beta/////////////

// build the select query
if (isset($execute_search) && $execute_search === '1'){ // it's a search result, the user has just filled the search form, so we have to build the select query
//if (!isset($where_clause)){ // it's a search result, the user has just filled the search form, so we have to build the select query
$where_clause = build_where_clause($_POST, $fields_labels_ar, $table_name);
} // end if


elseif (!isset($where_clause)) { // when I call index for the first time
$where_clause = '';
} // end else

////////////////now here is my addition//////////////////////////////////////////////////////////////////////////////////////////

//this section defines the date for one month ago from today and then waits for the 'lastmonth' $whereclause command then substitutes the recalulated date for the search

// get the current timestamp into an array
$timestamp = time();
$date_time_array = getdate($timestamp);

$hours = $date_time_array['hours'];
$minutes = $date_time_array['minutes'];
$seconds = $date_time_array['seconds'];
$month = $date_time_array['mon'];
$day = $date_time_array['mday'];
$year = $date_time_array['year'];

// use mktime to recreate the unix timestamp
// subtract one month
$timestamp = mktime($hours,$minutes,$seconds,$month - 1,$day,$year);
$lastmonth = strftime('%Y-%m-%d',$timestamp);
$lastmonth_formated = strftime('%A %B %d, %Y',$timestamp);

//this is the search to be executed
$lastmonth_whereclause = "Date > '$lastmonth'";

//this is the conditions in which the search will be executed

if ($where_clause == "Date=\"lastmonth\"") {
$where_clause = $lastmonth_whereclause;
} else {
$where_clause = $where_clause;
}


Now to trigger this search i use:
http://www.mysite.com/dadabik/index.php?function=search&where_clause=Date="lastmonth"&page=0&table_name=mytable

I'm not much of a coder but this is working great for me!!

 
Top