Hello,
I work on a website which shows a users trades.
I want to give the user an option to filter the trades. Here is a screenshot of the filtering page:
The user can select to see all trades starting from a selected date, until a selected date or between 2 selected dates.
The user can also select trades ope on selected weekdays. The user can select one weekday or any variation of weekdays.
The user can also select to filter trades by trade open hour
Here is the code which processes the form data
//////////////////////////////////////////////////////////////////////////////////////////////////////
/// Get MIN and MAX dates in case when start date / end date were not specified in filtering form ///
//////////////////////////////////////////////////////////////////////////////////////////////////////
$minmax = get_min_max_dates();
//print_r($minmax);
foreach ($minmax as $ckey=>$cval){
$min_date = $cval['startDate'];
$max_date = $cval['endDate'];
}
//////////////////////////////////////////////////////////////////////////////////////
/////// code for period ///////
/////// Insert period form data in variables for sql query ///////
//////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
//// filter is selected. From date - selected. To date - not selected ////
//// meaning all dates from trading start date until the end date ////
////////////////////////////////////////////////////////////////////////////////////
if($_POST['period'] == 'filter'){
if(!empty(trim($_POST['start_date'])) && (empty(trim($_POST['end_date'])))) {
//echo 'start_date: '.trim($_POST['start_date']);
$start_date = trim($_POST['start_date']);
$end_date = $max_date;
////////////////////////////////////////////////////////////////////////////////////
//// filter is selected. From date - selected. To date - selected ////
//// meaning all dates from selected start date until selected end date ////
////////////////////////////////////////////////////////////////////////////////////
}elseif(!empty(trim($_POST['start_date'])) && (!empty(trim($_POST['end_date'])))){
//echo'start_date: '.trim($_POST['start_date']).'<br> end_date: '.trim($_POST['end_date']);
$start_date = trim($_POST['start_date']);
$end_date = trim($_POST['end_date']);
////////////////////////////////////////////////////////////////////////////////
//// filter is selected. From date - not selected. To date - selected ////
//// meaning all dates from start of trading until the date selected ////
////////////////////////////////////////////////////////////////////////////////
}elseif(empty(trim($_POST['start_date'])) && (!empty(trim($_POST['end_date'])))){
//echo 'End date:' .trim($_POST['end_date']);
$start_date = $min_date;
$end_date = trim($_POST['end_date']);
//////////////////////////////////////////////////////////////////////////////////////////////////
//// filter is selected. from date - not selected. to date - not selected /////
//// ************ THIS SELECTION CREATES AN ERROR ************ /////
//// since the user selected the option for a specific period but didn'n select any dates /////
//////////////////////////////////////////////////////////////////////////////////////////////////
}elseif(empty(trim($_POST['start_date'])) && (empty(trim($_POST['end_date'])))){
echo '<b>ERROR</b>:<br> At least one date (start date / End date) munt be inserted<br>
<b> or</b><br> select: <i>All(default option)</i> in desired peroid';
die();
}
}else {
///////////////////////////////////////////////////////////////////////////////////
//// filter is selected. THe default option - All - is selected. /////
///////////////////////////////////////////////////////////////////////////////////
//echo 'all';
$period_selest = false;
$start_date = $min_date;
$end_date = $max_date;
}
/////////////////////////////////////////////////////////////////////////
//// code for days ////
//// Insert intraday form data in variables for sql query ////
/////////////////////////////////////////////////////////////////////////
if(isset($_POST['weekday'])) {
$day_select = true;
$days = join(",", $_POST['weekday']);
}else{
$day_select = false;
$days = [0,1,2,3,4,5,6];
$days = join(",", $days);
}
///////////////////////////////////////////////////////////////////
/// code for intraday ////////
/// Insert intraday form data in variables for sql query ////////
///////////////////////////////////////////////////////////////////
if(isset($_POST['intraday'])){
$hours = ($_POST['intraday']);
switch ($hours) {
case "am":
$hour_start = '00:00';
$hour_end = '11:59';
//echo $hour_start.'<br>';
//echo $hour_end;
break;
case "pm":
$hour_start = '12:00';
$hour_end = '23:59';
//echo $hour_start.'<br>';
//echo $hour_end;
break;
case "on":
$hour_start = ($_POST['start']);
$hour_end = ($_POST['end']);
//echo $hour_start.'<br>';
//echo $hour_end;
break;
}//End switch ($hours)
}//End if(isset($_POST['intraday'])
else{
$hour_start = '00:00';
$hour_end = '23:59';
$intraday_select = false;
}
I want to insert $start_date, $end_date, $days, $hour_start, $hour_end
into a table so that a user can seee various trades e.g/ EUR/USD trades or DAX index trades using the selected filtering criteria without selecting them over and over again until a new filtering criteria is selected.
- Is it correct to save dates an time as text ?
- My biggest problem is how to insert the $days array into the database?
as it can be (1), (1, 2, 4), or (2, 3, 4, 5). in other words it can be a 1 item array to 5 items array