-
Posts
254 -
Joined
-
Last visited
Everything posted by Moorcam
-
$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
-
Hi folks, Getting the following error in Console when submitting data to MySQL via Bootstrap Modal: VM6553:1 Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at Object.success (tickets.php:391) at j (datatables.min.js:14) at Object.fireWith [as resolveWith] (datatables.min.js:14) at x (datatables.min.js:17) at XMLHttpRequest.b (datatables.min.js:17) Here is my JS <script> $(document).ready(function() { // add $(document).on("click", "#submit", function() { var title = $('#title').val(); var body = $('#body').val(); $.ajax({ url: "includes/add-ticket.php", type: "POST", catch: false, data: { added: 1, title: title, body: body }, success: function(dataResult) { var dataResult = JSON.parse(dataResult); if (dataResult.status == 1) { $('#add_ticket').modal().hide(); swal("Ticket Submitted", { icon: "success", }).then((result) => { location.reload(); }); } } }); }); }); </script> Data is being submitted but the modal doesn't close after submit and the above error shows in Console. Can anyone help with this? Google doesn't want to help. Cheers
-
I have never tried it myself to be honest but here is a useful article that may help you: https://www.plus2net.com/php_tutorial/whois-online.php
-
Have you tried with a Modal or JS alert? Probably use a Session or Cookie to determine who is online?
-
I see. Oh well. Not a biggie. Just wanted it displayed in the booking table on the site so end user can see which tour was booked. Thanks as always for your help. Always appreciated.
-
Working now. I am getting the ID now into the tour_id but also into the tour_name field. I need tour_name to go into tour_name. if(isset($_POST['new']) && $_POST['new']==1){ $tour_id = mysqli_real_escape_string($con, $_POST['tour_name']); $tour_name = mysqli_real_escape_string($con, $_POST['tour_name']); $customer_name = mysqli_real_escape_string($con, $_POST['customer_name']); $customer_address = mysqli_real_escape_string($con, $_POST['customer_address']); $customer_email = mysqli_real_escape_string($con, $_POST['customer_email']); $customer_phone = mysqli_real_escape_string($con, $_POST['customer_phone']); $total_pax = mysqli_real_escape_string($con, $_POST['total_pax']); $status = mysqli_real_escape_string($con, $_POST['status']); $order_at = mysqli_real_escape_string($con, date("Y-m-d H:i:s")); $total_amount = mysqli_real_escape_string($con, $_POST['total_amount']); $query="insert into bookings (`tour_id`, `tour_name`, `customer_name`, `customer_address`, `customer_email`, `customer_phone`, `total_pax`, `status`, `order_at`, `total_amount`)values ('$tour_id', '$tour_name', '$customer_name', '$customer_address', '$customer_email', '$customer_phone', '$total_pax', '$status', '$order_at', '$total_amount')"; mysqli_query($con,$query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ $message = '<p class="text-success"><i class="fa fa-check"></i> - Record Inserted Successfully</p>'; } }
-
I call it Irish Brain Syndrome. Here is the fill add-booking.php <?php include_once('includes/header.php'); if(isset($_POST['new']) && $_POST['new']==1){ $sql = "SELECT id FROM jobs"; $result = $con->query($sql); while(list($id) = mysqli_fetch_row($result)){ } $tour_id = isset($_GET['id']) ? $_GET['id'] : ''; $tour_name = mysqli_real_escape_string($con, $_POST['tour_name']); $customer_name = mysqli_real_escape_string($con, $_POST['customer_name']); $customer_address = mysqli_real_escape_string($con, $_POST['customer_address']); $customer_email = mysqli_real_escape_string($con, $_POST['customer_email']); $customer_phone = mysqli_real_escape_string($con, $_POST['customer_phone']); $total_pax = mysqli_real_escape_string($con, $_POST['total_pax']); $status = mysqli_real_escape_string($con, $_POST['status']); $order_at = mysqli_real_escape_string($con, date("Y-m-d H:i:s")); $total_amount = mysqli_real_escape_string($con, $_POST['total_amount']); $query="insert into bookings (`tour_id`, `tour_name`, `customer_name`, `customer_address`, `customer_email`, `customer_phone`, `total_pax`, `status`, `order_at`, `total_amount`)values ('$tour_id', '$tour_name', '$customer_name', '$customer_address', '$customer_email', '$customer_phone', '$total_pax', '$status', '$order_at', '$total_amount')"; mysqli_query($con,$query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ $message = '<p class="text-success"><i class="fa fa-check"></i> - Record Inserted Successfully</p>'; } } ?> <!-- Header--> <div class="breadcrumbs"> <div class="col-sm-4"> <div class="page-header float-left"> <div class="page-title"> <h1>Bookings</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>Booking <?php if($message = isset($message) ? $message : ''){ printf($message); } ?></small></div> <div class="card-body card-block"> <form role="form" method="post" name="add_tour" id="add_tour" action"" > <input type="hidden" name="new" value="1" /> <div class="modal-body"> <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="customer_name" class=" form-control-label">Customer Name</label><input type="text" id="customer_name" name="customer_name" placeholder="Customer Name" class="form-control"> </div> </div> <div class="col-6"> <div class="form-group"><label for="customer_address" class=" form-control-label">Customer Address</label> <input type="text" class="form-control" id="customer_address" name="customer_address" placeholder="Customer's Address" > </div> </div> </div> <div class="row form-group"> <div class="col-6"> <div class="form-group"><label for="total_pax" class=" form-control-label">Pax</label> <input type="text" id="total_pax" name="total_pax" placeholder="How many passengers?" class="form-control"> </div> </div> <div class="col-6"> <div class="form-group"><label for="total_amount" class=" form-control-label">Price</label><input type="text" id="total_amount" name="total_amount" placeholder="0.00" class="form-control"> </div> </div> </div> <div class="row form-group"> <div class="col-6"> <div class="form-group origin" ><label for="customer_email" class=" form-control-label">Customer Email</label><input type="email" id="customer_email" name="customer_email" placeholder="Customer Email" class="form-control"></div> </div> <div class="col-6"> <div class="form-group"><label for="customer_phone" class=" form-control-label">Customer Phone</label><input type="phone" id="customer_phone" name="customer_phone" placeholder="Customer Phone" class="form-control"></div> </div> </div> <div class="row form-group"> <div class="col-6"> <div class="form-group origin" ><label for="status" class=" form-control-label">Payment Status</label> <select class="form-control" id="status" name="status"> <option value =""> == Choose One ==</option> <option value="PAID">PAID</option> <option value="UNPAID">UNPAID</option> </select> </div> </div> <div class="col-6"> <div class="form-group"><label for="tour_name" class=" form-control-label">Tour or Charter</label> <select class="form-control" id="tour_name" name="tour_name"> <option value="Select">== Select Tour or Charter ==</option> <?php $sql = "SELECT name, id FROM jobs"; $result = $con->query($sql); while(list($id, $name) = mysqli_fetch_row($result)){ ?> <option value="<?php echo $id ?>"><?php echo $name;?></option> <?php } ?> </select> </div> </div> </div> <div class="modal-footer"> <button type="reset" class="btn btn-warning">Clear Form</button> <button type="submit" name="submit" id="submit" class="btn btn-primary">Confirm</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/bing.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> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script src="https://cdn.tiny.cloud/1/sw6bkvhzd3ev4xl3u9yx3tzrux4nthssiwgsog74altv1o65/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script> </body> </html>
-
Did that. Now dropdown only shows id
-
Ah I see. Tried that. Getting undefined variable id in the <option value part: <?php $sql = "SELECT id, name FROM jobs"; $result = $con->query($sql); while(list($name) = mysqli_fetch_row($result)){ ?> <option value="<?php echo $id ?>"><?php echo $name;?></option> <?php } ?> I appreciate your help.