Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Holiday Dates 1

Status
Not open for further replies.

pastorandy

IS-IT--Management
Nov 2, 2006
84
GB
Hi
Does anyone know of any script examples where you are able to select multiple dates and have them available to populate into a simple holiday table.

My application takes a holiday date for an employee in the basic format into a holiday table:

employee_id, holiday_date

I could just have a select box with dates to get one holiday date but wanted to know if anyone knows of a better solution for selecting multiple dates (i.e like a week) for example.
 
i would use a two fields (to and from) and attach a javascript date picker to both.

i have found, for very similar activities, that it is best all round to store the holiday days between the to and from as separate entries in a join table. so you have a table with

Code:
day1->employeeID
day2->employeeID
day3->employeeID
 
Hi
If i had to write the application again that's what I would do. Thanks!

Any other ideas for doing this one single dates for now?
 
andy

i'm confused! i think you've got the table right. just two colums: employee and holiday date.

in the presentation layer I would have two date boxes. then use the middle layer to construct an array of queries and insert them within a loop

Code:
<?php
$to = rtnDate($_POST['end']);
$from = rtnDate($_POST['from']);
//delete existing holiday records
$dbTo = rtnDBDate($to);
$dbFrom = rtnDBDate($from);
mysql_query("delete from holidaytable where employeeID='$employeeID' and holiday between '$dbFrom' and '$dbTo'");

$date = $from;
while{$date <= $to){
	$dbDate = rtnDBDate($date);
	mysql_query("Insert into holidaytable set employeeID='$employeeID', holiday='$dbDate'";);
	$date = strtotime("+1 day", $date);
}

function rtnDBDate ($input){
	return mysql_escape_string(date('Y-m-d'. $input));
}
function rtnDate($input){
        return strtotime(trim($input)));
}
?>
 
Hi

It's just that I have code and queries that just rely upon one date from that table to function properly and it's taken ages just to get that working.

Not sure I want to spend ages again trying to get it to work with a 'to' and 'from' date although that is the better solution.
 
you don't need to spend ages! just use the construct and the loop that i proposed above. it should just drop in.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top