-
Posts
189 -
Joined
-
Last visited
Everything posted by Moorcam
-
*Red Faced* Sorry. I thought you meant a Var dump Here you go. Hope this is what you are after: CREATE TABLE `stafftime` ( `time_id` int(11) NOT NULL, `sheet_id` int(11) NOT NULL, `staff_date` date NOT NULL, `time_start` varchar(20) NOT NULL, `time_end` varchar(20) NOT NULL, `break_time` varchar(20) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `stafftime` -- INSERT INTO `stafftime` (`time_id`, `sheet_id`, `staff_date`, `time_start`, `time_end`, `break_time`) VALUES (1040, 141826, '2021-09-19', '06:00', '17:00', '1:00'), (1041, 671766, '2021-09-19', '09:30', '17:30', '1:00'), (1042, 1080, '2021-09-19', '09:30', '17:30', '1:00'); -- -------------------------------------------------------- -- -- Table structure for table `timesheets` -- CREATE TABLE `timesheets` ( `timesheet_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `week_ending` datetime NOT NULL, `timesheet_comment` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `timesheets` -- INSERT INTO `timesheets` (`timesheet_id`, `user_id`, `week_ending`, `timesheet_comment`) VALUES (1050, 9, '2021-10-10 00:00:00', 'Just a test'), (1051, 9, '2021-09-19 00:00:00', 'Just a test'), (1052, 9, '2021-09-19 00:00:00', 'Just a test'); -- -- Indexes for dumped tables -- -- -- Indexes for table `stafftime` -- ALTER TABLE `stafftime` ADD PRIMARY KEY (`time_id`), ADD KEY `timesheet_id` (`sheet_id`); -- -- Indexes for table `timesheets` -- ALTER TABLE `timesheets` ADD PRIMARY KEY (`timesheet_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `stafftime` -- ALTER TABLE `stafftime` MODIFY `time_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1043; -- -- AUTO_INCREMENT for table `timesheets` -- ALTER TABLE `timesheets` MODIFY `timesheet_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1053; COMMIT;
-
Here is a var_dump of the $result object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(12) ["lengths"]=> array(12) { [0]=> int(1) [1]=> int(4) [2]=> int(19) [3]=> int(1) [4]=> int(7) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) } ["num_rows"]=> int(3) ["type"]=> int(0) } object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(12) ["lengths"]=> array(12) { [0]=> int(1) [1]=> int(4) [2]=> int(19) [3]=> int(1) [4]=> int(7) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) } ["num_rows"]=> int(3) ["type"]=> int(0) } object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(12) ["lengths"]=> array(12) { [0]=> int(1) [1]=> int(4) [2]=> int(19) [3]=> int(1) [4]=> int(7) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) } ["num_rows"]=> int(3) ["type"]=> int(0) } And a var_dump of $sql string(494) "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=9" string(494) "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=9" string(494) "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=9" I really appreciate your time and effort man.
-
Thanks mate. Great reading. Very informative. It appears my query is not getting the data from stafftime. Populating from the other two tables fine but anything from stafftime is just not happening. $session = $_SESSION['ID']; $sql = "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=$session"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) {
-
You will probably need something like this. But will need to work out the actual outline of the Frame to make it look like a TV: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_responsive_iframe_169
-
if(isset($row['time_start']) && $row['time_end'] && $row['break_time'] != "") { $time_start = new DateTime($row['time_start']); $time_end = new DateTime($row['time_end']); list($h, $m) = explode(":", $row['break_time']); $break_time = new DateInterval("PT{$h}H{$m}M"); $time_worked = $time_start->add($break_time)->diff($time_end); echo $time_worked; } Have also tried this and nothing.
-
Howdy guys, First of all, thanks so much for your help so far, especially yesterday. My wife and kids would tell you I was ropeable. Following Barand's advice and idea on my previous post, I have decided to break things up and put them into separate tables to make it easier to process. All is working fine but Hours Worked do not WERK (work), I am trying an accent Here's the code that called the timesheet submitted by a driver for one day. It is showing to the submitter based on their session id. $session = $_SESSION['ID']; $sql = "SELECT timesheets.*, users.*, staff_time.*, timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN staff_time ON timesheets.timesheet_id = staff_time.sheet_id WHERE id=$session"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { Here is where I am trying to display the hours worked: <td><?php echo $row['hrs_worked']; ?></td> But nothing shows. No errors, nothing in Console either. I am obviously doing this wrong. As mentioned in my last post, I am new to this JOIN thingy-ma-jig. I know this following piece is meant to calculate between start, end and break. Not sure if that's happening either. timediff(timediff(time_end, time_start), break_time) as hrs_worked Any guidance, as always is appreciated.
-
Probably years ago lol
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Got it: $sql = "SELECT timesheets.*, users.*, staff_time.*, timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN staff_time ON timesheets.timesheet_id = staff_time.timesheet_id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { Thanks guys for your patience etc. Had never heard of JOIN this and that until it was mentioned on these forums a couple months ago :D
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
$sql = "SELECT timesheets.*, users.*, staff_time.* FROM timesheets INNER JOIN users ON users.user_id = timesheets.user_id INNER JOIN staff_time ON staff_time.timesheet_id = timesheet.timesheet_id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { Still no good.
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
I can't get it. Been fiddling, moving, swapping, searching google, trying what other people have tried, and my Irish Brain Syndrome, coupled with the lack thereof said Guinness fix, results in a Nadda approach. 😕
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Ok, have tried what was suggested and just getting errors: Warning: Attempt to read property "num_rows" on bool in D:\xampp\htdocs\protour\admin\timesheets.php on line 60 All tables have a value. Have also tried the following with same error: $sql = "SELECT timesheets.*, users.*, st.* FROM staff_time AS st LEFT JOIN users LEFT JOIN timesheets ON st.time_id ON users.user_id = timesheets.timesheet_id WHERE timesheet_id = $timesheet_id LIMIT 1"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { I give up
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Ignore above post. My brain is still fried
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Afternoon, Now that I have refreshed the brain cells, which don't work anyway, I decided to have a crack at this. At the moment I am trying to get data as below (suggested by your good self), and getting an error of Parse error: syntax error, unexpected identifier "concat" Here is the code I am using to get the data, which is just a modify of what Barand posted above: <?php SELECT concat(firstname,' ', lastname) as name , dayname(staff_date) as day , date_format(staff_date, '%b %d') as date , time_start , time_end , break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM driver_time JOIN timesheets USING (timesheet_id) JOIN users USING (user_id) WHERE week_ending = date ORDER BY user_id, staff_date; ?> Doing this the way Barand suggested, I think is definitely the way to go. If I can get past this I am having Guinness tonight
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Thanks mate. Will have a look at all this in the next day or so. It's like 1:30am now and my brain has literally fried.
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Awesome news. Now, what have you tried already?
-
This is getting annoying now. If I fill in the Start, Break and Finish times for Monday and Tuesday, it shows the correct Total Hours. But, if I add in Wednesday, it goes bonkers. Here is the full code. If anyone can figure it our, please be my guest. In the meantime, I feel like filling the Recycling Bin with diff this and diff that, <?php include_once('includes/header.php'); if(isset($_POST['submit_timesheet'])){//if the submit button is clicked $week_ending = mysqli_real_escape_string($con, $_POST['week_ending']); $staff_name = mysqli_real_escape_string($con, $_SESSION["USERNAME"]); $monday_start = mysqli_real_escape_string($con, $_POST['monday_start']); $monday_finish = mysqli_real_escape_string($con, $_POST['monday_finish']); $tuesday_start = mysqli_real_escape_string($con, $_POST['tuesday_start']); $tuesday_finish = mysqli_real_escape_string($con, $_POST['tuesday_finish']); $wednesday_start = mysqli_real_escape_string($con, $_POST['wednesday_start']); $wednesday_finish = mysqli_real_escape_string($con, $_POST['wednesday_finish']); $thursday_start = mysqli_real_escape_string($con, $_POST['thursday_start']); $thursday_finish = mysqli_real_escape_string($con, $_POST['thursday_finish']); $friday_start = mysqli_real_escape_string($con, $_POST['friday_start']); $friday_finish = mysqli_real_escape_string($con, $_POST['friday_finish']); $saturday_start = mysqli_real_escape_string($con, $_POST['saturday_start']); $saturday_finish = mysqli_real_escape_string($con, $_POST['saturday_finish']); $sunday_start = mysqli_real_escape_string($con, $_POST['sunday_start']); $sunday_finish = mysqli_real_escape_string($con, $_POST['sunday_finish']); $total_hours = mysqli_real_escape_string($con, $_POST['total_hours']); $timesheet_comment = mysqli_real_escape_string($con, $_POST['timesheet_comment']); $ins_query="insert into timesheets (`week_ending`, `staff_name`, `monday_start`, `monday_finish`, `tuesday_start`, `tuesday_finish`, `wednesday_start`, `wednesday_finish`, `thursday_start`, `thursday_finish`, `friday_start`, `friday_finish`, `saturday_start`, `saturday_finish`, `sunday_start`, `sunday_finish`, `total_hours`, `timesheet_comment`) values ( '$week_ending', '$staff_name', '$monday_start', '$monday_finish', '$tuesday_start', '$tuesday_finish', '$wednesday_start', '$wednesday_finish', '$thursday_start', '$thursday_finish', '$friday_start', '$friday_finish', '$saturday_start', '$saturday_finish', '$sunday_start', '$sunday_finish', '$total_hours', '$timesheet_comment' )"; mysqli_query($con,$ins_query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ $message = '<p class="text-success"><i class="fa fa-check"></i> - Timesheet Submitted Successfully</p>'; } } ?> <!-- Header--> <div class="breadcrumbs"> <div class="col-sm-4"> <div class="page-header float-left"> <div class="page-title"> <h1><i class="fa fa-clock"></i> Timesheets</h1> </div> </div> </div> <div class="col-sm-8"> </div> </div> <div class="content mt-3"> <div class="animated fadeIn"> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-header"><strong>Add </strong><small>Timesheet <?php if($message = isset($message) ? $message : ''){ printf($message); } ?></small></div> <div class="card-body card-block"> <form role="form" method="post" action=""> <input type="hidden" name="new" value="1" /> <div class="modal-body"> <p>Please make sure your start times and finish times are correct as it will effect your payments. Start time is start time at Depot and finish time is finish at Depot.<br />For days not worked please place 00:00 in time fields. </p> <div class="row form-group"> <div class="col-6"> <label for="driver_name" class=" form-control-label">Driver Name (required)</label> <input type="text" class="form-control" id="driver_name" name="driver_name" placeholder="" value="<?php echo $_SESSION['NAME']; ?>" required > </div> <div class="col-6"> <label for="week_ending" class=" form-control-label">Week Ending (required)</label> <input type="date" class="form-control" id="week_ending" name="week_ending" placeholder="" value="<?php echo isset($_POST['week_ending']) ? $_POST['week_ending'] : '' ?>" required > </div> </div> <hr> <h3>Monday</h3> <div class="row form-group"> <div class="col-4"> <label for="monday_start" class=" form-control-label">Start Time</label> <input type="text" class="form-control" id="monday_start" name="monday_start" placeholder="" value="<?php echo isset($_POST['monday_start']) ? $_POST['monday_start'] : '' ?>" > </div> <div class="col-4"> <label for="monday_break" class=" form-control-label">Break Period</label> <input type="text" class="form-control" id="monday_break" name="monday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['monday_break']) ? $_POST['monday_break'] : '' ?>" > </div> <div class="col-4"> <label for="monday_finish" class=" form-control-label">Finish Time</label> <input type="text" class="form-control" id="monday_finish" name="monday_finish" placeholder="" value="<?php echo isset($_POST['monday_finish']) ? $_POST['monday_finish'] : '' ?>" > </div> </div> <?php // MONDAY CALCULATIONS if(isset($_POST['monday_start']) && $_POST['monday_finish'] && $_POST['monday_break'] != "") { $monday_start = new DateTime($_POST['monday_start']); $monday_finish = new DateTime($_POST['monday_finish']); list($h, $m) = explode(":", $_POST['monday_break']); $monday_break = new DateInterval("PT{$h}H{$m}M"); $mondiff = $monday_start->add($monday_break)->diff($monday_finish); ?> <div class="form-group"> <label for="mondiff" class=" form-control-label">Monday Hours</label> <input type="text" readonly class="form-control" name="mondiff" value="<?php echo $mondiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Tuesday</h3> <div class="row form-group"> <div class="col-4"> <label for="tuesday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="tuesday_start" name="tuesday_start" placeholder="" value="<?php echo isset($_POST['tuesday_start']) ? $_POST['tuesday_start'] : '' ?>" > </div> <div class="col-4"> <label for="tuesday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="tuesday_break" name="tuesday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['tuesday_break']) ? $_POST['tuesday_break'] : '' ?>" > </div> <div class="col-4"> <label for="tuesday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="tuesday_finish" name="tuesday_finish" placeholder="" value="<?php echo isset($_POST['tuesday_finish']) ? $_POST['tuesday_finish'] : '' ?>" > </div> </div> <?php // TUESDAY CALCULATIONS if(isset($_POST['tuesday_start']) && $_POST['tuesday_finish'] && $_POST['tuesday_break'] != "") { $tuesday_start = new DateTime($_POST['tuesday_start']); $tuesday_finish = new DateTime($_POST['tuesday_finish']); list($h, $m) = explode(":", $_POST['tuesday_break']); $tuesday_break = new DateInterval("PT{$h}H{$m}M"); $tuediff = $tuesday_start->add($tuesday_break)->diff($tuesday_finish); ?> <div class="form-group"> <label for="tuediff" class=" form-control-label">Tuesday Hours</label> <input type="text" readonly class="form-control" name="tuediff" value="<?php echo $tuediff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Wednesday</h3> <div class="row form-group"> <div class="col-4"> <label for="wednesday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="wednesday_start" name="wednesday_start" placeholder="" value="<?php echo isset($_POST['wednesday_start']) ? $_POST['wednesday_start'] : '' ?>" > </div> <div class="col-4"> <label for="wednesday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="wednesday_break" name="wednesday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['wednesday_break']) ? $_POST['wednesday_break'] : '' ?>" > </div> <div class="col-4"> <label for="wednesday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="wednesday_finish" name="wednesday_finish" placeholder="" value="<?php echo isset($_POST['wednesday_finish']) ? $_POST['wednesday_finish'] : '' ?>" > </div> </div> <?php // WEDNESDAY CALCULATIONS if(isset($_POST['wednesday_start']) && $_POST['wednesday_finish'] && $_POST['wednesday_break'] != "") { $wednesday_start = new DateTime($_POST['wednesday_start']); $wednesday_finish = new DateTime($_POST['wednesday_finish']); list($h, $m) = explode(":", $_POST['wednesday_break']); $wednesday_break = new DateInterval("PT{$h}H{$m}M"); $weddiff = $wednesday_start->add($wednesday_break)->diff($wednesday_finish); ?> <div class="form-group"> <label for="weddiff" class=" form-control-label">Wednesday Hours</label> <input type="text" readonly class="form-control" name="weddiff" value="<?php echo $weddiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Thursday</h3> <div class="row form-group"> <div class="col-4"> <label for="thursday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="thursday_start" name="thursday_start" placeholder="" value="<?php echo isset($_POST['thursday_start']) ? $_POST['thursday_start'] : '' ?>" > </div> <div class="col-4"> <label for="thursday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="thursday_break" name="thursday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['thursday_break']) ? $_POST['thursday_break'] : '' ?>" > </div> <div class="col-4"> <label for="thursday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="thursday_finish" name="thursday_finish" placeholder="" value="<?php echo isset($_POST['thursday_finish']) ? $_POST['thursday_finish'] : '' ?>" > </div> </div> <?php // THURSDAY CALCULATIONS if(isset($_POST['thursday_start']) && $_POST['thursday_finish'] && $_POST['thursday_break'] != "") { $thursday_start = new DateTime($_POST['thursday_start']); $thursday_finish = new DateTime($_POST['thursday_finish']); list($h, $m) = explode(":", $_POST['thursday_break']); $thursday_break = new DateInterval("PT{$h}H{$m}M"); $thurdiff = $thursday_start->add($thursday_break)->diff($thursday_finish); ?> <div class="form-group"> <label for="thurdiff" class=" form-control-label">Thursday Hours</label> <input type="text" readonly class="form-control" name="thurdiff" value="<?php echo $thurdiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Friday</h3> <div class="row form-group"> <div class="col-4"> <label for="friday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="friday_start" name="friday_start" placeholder="" value="<?php echo isset($_POST['friday_start']) ? $_POST['friday_start'] : '' ?>" > </div> <div class="col-4"> <label for="friday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="friday_break" name="friday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['friday_break']) ? $_POST['friday_break'] : '' ?>" > </div> <div class="col-4"> <label for="friday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="friday_finish" name="friday_finish" placeholder="" value="<?php echo isset($_POST['friday_finish']) ? $_POST['friday_finish'] : '' ?>" > </div> </div> <?php // FRIDAY CALCULATIONS if(isset($_POST['friday_start']) && $_POST['friday_finish'] && $_POST['friday_break'] != "") { $friday_start = new DateTime($_POST['friday_start']); $friday_finish = new DateTime($_POST['friday_finish']); list($h, $m) = explode(":", $_POST['friday_break']); $friday_break = new DateInterval("PT{$h}H{$m}M"); $fridiff = $friday_start->add($friday_break)->diff($friday_finish); ?> <div class="form-group"> <label for="fridiff" class=" form-control-label">Friday Hours</label> <input type="text" readonly class="form-control" name="fridiff" value="<?php echo $fridiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Saturday</h3> <div class="row form-group"> <div class="col-4"> <label for="saturday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="saturday_start" name="saturday_start" placeholder="" value="<?php echo isset($_POST['saturday_start']) ? $_POST['saturday_start'] : '' ?>" > </div> <div class="col-4"> <label for="saturday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="saturday_break" name="saturday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['saturday_break']) ? $_POST['saturday_break'] : '' ?>" > </div> <div class="col-4"> <label for="saturday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="saturday_finish" name="saturday_finish" placeholder="" value="<?php echo isset($_POST['saturday_finish']) ? $_POST['saturday_finish'] : '' ?>" > </div> </div> <?php // SATURDAY CALCULATIONS if(isset($_POST['saturday_start']) && $_POST['saturday_finish'] && $_POST['saturday_break'] != "") { $saturday_start = new DateTime($_POST['saturday_start']); $saturday_finish = new DateTime($_POST['saturday_finish']); list($h, $m) = explode(":", $_POST['saturday_break']); $saturday_break = new DateInterval("PT{$h}H{$m}M"); $satdiff = $saturday_start->add($saturday_break)->diff($saturday_finish); ?> <div class="form-group"> <label for="satdiff" class=" form-control-label">Saturday Hours</label> <input type="text" readonly class="form-control" name="satdiff" value="<?php echo $satdiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Sunday</h3> <div class="row form-group"> <div class="col-4"> <label for="sunday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="sunday_start" name="sunday_start" placeholder="" value="<?php echo isset($_POST['sunday_start']) ? $_POST['sunday_start'] : '' ?>" > </div> <div class="col-4"> <label for="sunday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="sunday_break" name="sunday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['sunday_break']) ? $_POST['sunday_break'] : '' ?>" > </div> <div class="col-4"> <label for="sunday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="sunday_finish" name="sunday_finish" placeholder="" value="<?php echo isset($_POST['sunday_finish']) ? $_POST['sunday_finish'] : '' ?>" > </div> </div> <?php // SATURDAY CALCULATIONS if(isset($_POST['sunday_start']) && $_POST['sunday_finish'] && $_POST['sunday_break'] != "") { $sunday_start = new DateTime($_POST['sunday_start']); $sunday_finish = new DateTime($_POST['sunday_finish']); list($h, $m) = explode(":", $_POST['sunday_break']); $sunday_break = new DateInterval("PT{$h}H{$m}M"); $sundiff = $sunday_start->add($sunday_break)->diff($sunday_finish); ?> <div class="form-group"> <label for="sundiff" class=" form-control-label">Sunday Hours</label> <input type="text" readonly class="form-control" name="sundiff" value="<?php echo $sundiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <?php if(isset($_POST['calculate']) != ""){ class times_counter { private $hou = 0; private $min = 0; private $sec = 0; private $totaltime = '00:00:00'; public function __construct($times){ if(is_array($times)){ $length = sizeof($times); for($x=0; $x <= $length; $x++){ $split = explode(":", @$times[$x]); $this->hou += (int)$split[0]; $this->min += @$split[1]; $this->sec += @$split[2]; } $seconds = $this->sec % 60; $minutes = $this->sec / 60; $minutes = (integer)$minutes; $minutes += $this->min; $hours = $minutes / 60; $minutes = $minutes % 60; $hours = (integer)$hours; $hours += $this->hou % 24; $this->totaltime = $hours.":".$minutes; } } public function get_total_time(){ return $this->totaltime; } } $times = array( $mondiff->format('%H:%I'), $tuediff->format('%H:%I'), $weddiff->format('%H:%I'), $thurdiff->format('%H:%I'), $fridiff->format('%H:%I'), $satdiff->format('%H:%I'), $sundiff->format('%H:%I'), ); $counter = new times_counter($times); ?> <div class="row form-group"> <div class="col-6"> <div class="form-group"> <label for="total_hours" class=" form-control-label">Total Hours (required)</label> <input name="total_hours" id="total_hours" readonly class="form-control" value= "<?php echo $counter->get_total_time(); ?>" /> </div> </div> <?php } ?> <div class="col-6"> <div class="form-group"> <label for="timesheet_comment" class=" form-control-label">Comment (optional)</label> <input type="text" class="form-control" id="timesheet_comment" name="timesheet_comment" placeholder="" value="<?php echo isset($_POST['timesheet_comment']) ? $_POST['timesheet_comment'] : '' ?>" > </div> </div> </div> <div class="modal-footer"> <button type="submit" name="calculate" id="calculate" class="btn btn-primary">Calculate Hours</button> <button type="submit" name="submit_timesheet" id="submit_timesheet" class="btn btn-primary">Submit Timesheet</button> </div> </form> </div> </div> </div><!-- .animated --> </div><!-- .content --> </div><!-- /#right-panel --> <!-- Right Panel --> <script src="assets/js/vendor/jquery-2.1.4.min.js"></script> <script src="assets/js/popper.min.js"></script> <script src="assets/js/plugins.js"></script> <script src="assets/js/main.js"></script> <script src="assets/js/lib/data-table/datatables.min.js"></script> <script src="assets/js/lib/data-table/dataTables.bootstrap.min.js"></script> <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script> <script src="assets/js/lib/data-table/buttons.bootstrap.min.js"></script> <script src="assets/js/lib/data-table/jszip.min.js"></script> <script src="assets/js/lib/data-table/pdfmake.min.js"></script> <script src="assets/js/lib/data-table/vfs_fonts.js"></script> <script src="assets/js/lib/data-table/buttons.html5.min.js"></script> <script src="assets/js/lib/data-table/buttons.print.min.js"></script> <script src="assets/js/lib/data-table/buttons.colVis.min.js"></script> <script src="assets/js/lib/data-table/datatables-init.js"></script> </body> </html> Have a good day/evening/night/morning etc....
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Yeah seems to be ok if times are inserted in 24hr format. I am on localhost (xampp) so the error shows as Undefined Array Key but loaded onto live server and it shows as Undefined Variable. Bit strange but hey. So is Covid
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
So, I added up all days, which gave a total of 32:00, which included the breaks. Total Hours show as 8:00 <?php if(empty($_POST['monday_start'])) { ?> <input type="text" class="form-control" id="monday_start" name="monday_start" placeholder="" value="00:00" > <?php }else{ ?> <input type="text" class="form-control" id="monday_start" name="monday_start" placeholder="" value="<?php echo isset($_POST['monday_start']) ? $_POST['monday_start'] : '' ?>" > <?php } ?> Still shows: Undefined array key '$mondiff'...
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
So for example, for Monday: Start: 09:00 Break: 1:00 Finish: 17:00 Have also tried 09:00 AM etc Tried it. That's why I asked.
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Hi folks, Have the following, which is part of a script I am working on to calculate working hours minus break time. However, it's not calculating the correct result. For example, if I worked 12 hours, take away 1 hour break, should be 11 hours. But it will show it as something like 7 hours. Here is the part for Monday: <div class="col-lg-12"> <div class="card"> <div class="card-header"><strong>Add </strong><small>Timesheet <?php if($message = isset($message) ? $message : ''){ printf($message); } ?></small></div> <div class="card-body card-block"> <form role="form" method="post" action=""> <input type="hidden" name="new" value="1" /> <div class="modal-body"> <div class="row form-group"> <div class="col-6"> <label for="driver_name" class=" form-control-label">Driver Name (required)</label> <input type="text" class="form-control" id="driver_name" name="driver_name" placeholder="" value="<?php echo $_SESSION['NAME']; ?>" required > </div> <div class="col-6"> <label for="week_ending" class=" form-control-label">Week Ending (required)</label> <input type="date" class="form-control" id="week_ending" name="week_ending" placeholder="" value="<?php echo isset($_POST['week_ending']) ? $_POST['week_ending'] : '' ?>" required > </div> </div> <hr> <h3>Monday</h3> <div class="row form-group"> <div class="col-4"> <label for="monday_start" class=" form-control-label">Start Time</label> <input type="text" class="form-control" id="monday_start" name="monday_start" placeholder="" value="<?php echo isset($_POST['monday_start']) ? $_POST['monday_start'] : '' ?>" > </div> <div class="col-4"> <label for="monday_start" class=" form-control-label">Break Period</label> <input type="text" class="form-control" id="monday_break" name="monday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['monday_break']) ? $_POST['monday_break'] : '' ?>" > </div> <div class="col-4"> <label for="monday_finish" class=" form-control-label">Finish Time</label> <input type="text" class="form-control" id="monday_finish" name="monday_finish" placeholder="" value="<?php echo isset($_POST['monday_finish']) ? $_POST['monday_finish'] : '' ?>" > </div> </div> <?php if(isset($_POST['monday_start']) && $_POST['monday_finish'] && $_POST['monday_break'] != "") { $monday_start = new DateTime($_POST['monday_start']); $monday_finish = new DateTime($_POST['monday_finish']); list($h, $m) = explode(":", $_POST['monday_break']); $monday_break = new DateInterval("PT{$h}H{$m}M"); $mondiff = $monday_start->add($monday_break)->diff($monday_finish); ?> <div class="form-group"> <label for="monday" class=" form-control-label">Monday Hours</label> <input type="text" readonly class="form-control" id="monday_hours" name="monday_hours" value="<?php echo $mondiff->format('%H:%I'); ?>"> </div> <?php } ?> Here is the calculating code: <?php if(isset($_POST['calculate']) != ""){ class times_counter { private $hou = 0; private $min = 0; private $sec = 0; private $totaltime = '00:00:00'; public function __construct($times){ if(is_array($times)){ $length = sizeof($times); for($x=0; $x <= $length; $x++){ $split = explode(":", @$times[$x]); $this->hou += (int)$split[0]; $this->min += @$split[1]; $this->sec += @$split[2]; } $seconds = $this->sec % 60; $minutes = $this->sec / 60; $minutes = (integer)$minutes; $minutes += $this->min; $hours = $minutes / 60; $minutes = $minutes % 60; $hours = (integer)$hours; $hours += $this->hou % 24; $this->totaltime = $hours.":".$minutes; } } public function get_total_time(){ return $this->totaltime; } } $times = array( $mondiff->format('%H:%I'), $tuediff->format('%H:%I'), $weddiff->format('%H:%I'), $thurdiff->format('%H:%I'), $fridiff->format('%H:%I'), $satdiff->format('%H:%I'), $sundiff->format('%H:%I'), ); $counter = new times_counter($times); ?> <div class="row form-group"> <div class="col-6"> <div class="form-group"> <label for="total_hours" class=" form-control-label">Total Hours (required)</label> <input name="total_hours" readonly class="form-control" value= "<?php echo $counter->get_total_time(); ?>" /> </div> </div> <?php } ?> Can someone with the geneius knowledge have a look and point me to where I am going wrong? Also, is there a way, to leave a time field blank and not have the above code crack the poops and call an Undefined Array Key on it? TIA
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Never mind. Stupid Irish Brain Syndrome. All good now with errors.
-
Thanks mate. Now getting this: Warning: Undefined array key 2 in D:\xampp\htdocs\protour\admin\add-timesheet.php on line 351 Warning: Undefined array key 1 in D:\xampp\htdocs\protour\admin\add-timesheet.php on line 350
-
Howdy folks, Calculating times between start and finish. Have them working but when calculating total hours - breaks I get the following error: Fatal error: Uncaught TypeError: Unsupported operand types: int + string in Here is the PHP code for the calculations: <?php if(isset($_POST['calculate']) != ""){ class times_counter { private $hou = 0; private $min = 0; private $sec = 0; private $totaltime = '00:00:00'; public function __construct($times){ if(is_array($times)){ $length = sizeof($times); for($x=0; $x <= $length; $x++){ $split = explode(":", @$times[$x]); $this->hou += @$split[0]; $this->min += @$split[1]; $this->sec += @$split[2]; } $seconds = $this->sec % 60; $minutes = $this->sec / 60; $minutes = (integer)$minutes; $minutes += $this->min; $hours = $minutes / 60; $minutes = $minutes % 60; $hours = (integer)$hours; $hours += $this->hou % 24; $this->totaltime = $hours.":".$minutes; } } public function get_total_time(){ return $this->totaltime; } } $times = array( $mondiff->format('%H:%I'), $tuediff->format('%H:%I'), $weddiff->format('%H:%I'), $thurdiff->format('%H:%I'), $fridiff->format('%H:%I'), $satdiff->format('%H:%I'), $sundiff->format('%H:%I'), ); $counter = new times_counter($times); ?> The line that is throwing the error is: $this->hou += @$split[0]; Any help with this would be appreciated. Cheers
-
Mate, you were spot on. I had it included inside a script for Google Directions API. Obviously, it doesn't like that. Removing it to it's own <script></script> resolved it. Thank you
-
Howdy folks, Getting this error in console when trying to print the contents of a div. get-directions.php:192 Uncaught ReferenceError: printDiv is not defined at HTMLInputElement.onclick Here is the Button for print and the Div wanting to print from: <div id="rightpanel" class="float-right col-md-4"></div> <input type="button" id="print" onclick="printDiv('rightpanel')" value="Print Directions" /> Here is the Script: function printDiv(rightpanel) { var disp_setting="toolbar=yes,location=no,"; disp_setting+="directories=yes,menubar=yes,"; disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; var content_vlue = document.getElementById(rightpanel).innerHTML; var docprint=window.open("","",disp_setting); docprint.document.open(); docprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'); docprint.document.write('"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); docprint.document.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'); docprint.document.write('<head><title>My Title</title>'); docprint.document.write('<style type="text/css">body{ margin:0px;'); docprint.document.write('font-family:verdana,Arial;color:#000;'); docprint.document.write('font-family:Verdana, Geneva, sans-serif; font-size:12px;}'); docprint.document.write('a{color:#000;text-decoration:none;} </style>'); docprint.document.write('</head><body onLoad="self.print()"><center>'); docprint.document.write(content_vlue); docprint.document.write('</center></body></html>'); docprint.document.close(); docprint.focus(); } Any help would be appreciated. Cheers