Jump to content

Moorcam

Members
  • Posts

    197
  • Joined

  • Last visited

Posts posted by Moorcam

  1. 11 minutes ago, requinix said:

    9am to 5pm minus one hour of break = 7 hours.

    So, I added up all days, which gave a total of 32:00, which included the breaks. Total Hours show as 8:00

    11 minutes ago, requinix said:

    Great. So what was that code?

                              <?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'...

  2. 13 minutes ago, requinix said:

    What exact inputs did you give for the various fields?

    So for example, for Monday:

    Start: 09:00 Break: 1:00 Finish: 17:00

    Have also tried 09:00 AM etc

    15 minutes ago, requinix said:

    By... writing code that says "if the field is empty then don't do stuff"?

    Tried it. That's why I asked.

  3. 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 :)

  4. 8 minutes ago, Barand said:

    PHP v8 doesn't let you mix indeterminate types, such as adding an empty string to an int.

    $a = 1;
    $b = '2';
    $c = '';
    
    echo $a + $b;         //  3          OK
    
    echo $a + $c;         //  Unsupported operand types: int + string
    
    echo $a + (int)$c;    //  1          OK

    Use a cast to int.

    $this->hou += (int)$split[0];

    That said, you really are doing the calculations the hard way

    $t1 = '09:30:00';
    $t2 = '17:15:00';
    
    $dt1 = new DateTime($t1);                    
    $dt2 = new DateTime($t2);
    echo $dt2->diff($dt1)->format('%H:%I:%S');            //  07:45:00 

     

    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

     

  5. 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

  6. 17 minutes ago, requinix said:

    That's the code for printDiv but obviously Javascript doesn't think you've defined it. Which could mean anything from that code living in a completely irrelevant file to that function being defined inside of some other code that hasn't run and/or runs in a different context than the window. Hard to say which without knowing more.

    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 :)

  7. 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 :)

  8. 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

  9. 1 minute ago, Barand said:

    "Tour_name" should not be in the booking table, just the id

     

    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.

  10. 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>';
        }
    
    }

     

  11. 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>

     

  12. 4 minutes ago, Barand said:

    They will see the name of the job they are booking in the dropdown, just as they do now. The only difference is what gets stored.

    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.

  13. Just now, Barand said:

    You're making it difficult for yourself.

    The tour/job name should not be in the booking table. The only place that should occur in your database is in the tour/job table. It is just the tour id that be in the booking table.

     +------------------+                  
     | booking          |                 +----------------+ 
     +------------------+                 |  tour/job      | 
     | booking_id       |                 +----------------+ 
     | tour_id          |>----------------| tour_id        | 
     | cust_name        |                 | tour_name      | 
     | cust_address     |                 +----------------+
     | order_at         |
     | ...              |
     | etc              |
     +------------------+

    When you create your dropdown options, the values of the options should be the id and not the name.

    Then all you do is insert $_POST['tour_name'] (which will actually be the id) into the booking data. Job done.

    Hi mate

    That is fine but the issue is, if an end user, such as a non-techy type person, was to create a booking from the backend, selecting an ID will make no sense to them. They will need to see the name of the job they are booking onto.

  14. Hi guys,

    I am trying to get data from the table "jobs" and insert its id and name into table "bookings"

    I can get the job "name" from "jobs", which is fine, using the following:

                               <select class="form-control" id="tour_name" name="tour_name">
                                   <option value="Select">== Select Tour or Charter ==</option>
    <?php
    $sql = "SELECT name FROM jobs";
    $result = $con->query($sql);
            while(list($name) = mysqli_fetch_row($result)){
           ?>
           <option value="<?php echo $name ?>"><?php echo $name;?></option>
    <?php
    }
    ?>
                               </select>

    However, when I click submit to insert into "bookings" everything goes in except "booking_id" which is "id" in "jobs". Hope this makes sense.

    I am using the following to insert:

    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>';
        }
    
    }

    Can anyone please lend a hand with this? 2 Days at it now and ready to hit the Guinness.

     

    Cheers,

    Dan

  15. 6 minutes ago, kicken said:

    Your class definition (class time_counter { ... }) should not be inside your if statement.  Move it outside to the top level.  There's no reason for it's declaration to be conditional.  No processing gets done when you declare the class, only when you instantiate it (new time_counter()).  So, declare the class unconditionally, instantiate it conditionally if needed.

    Hey kicken,

    Thanks for the reply.

    I did that and now get this:

    PHP Parse error:  syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST)

    Thanks for your help.

  16. Hi guys,

    I am trying to calculate hours a person works by calculating the values of text fields in a form.

    However, when I load the page I get "Class 'times_counter' not found.

    Here is the calculation code"

    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'),
       $tudiff->format('%H:%I'),
       $weddiff->format('%H:%I'),
       $thdiff->format('%H:%I'),
       $fridiff->format('%H:%I'),
       $satdiff->format('%H:%I'),
       $sundiff->format('%H:%I'),
    );
    $counter = new times_counter($times);

    I had this on an old project, which I no longer have but it worked then. Any ideas?

  17. Got is working

    <?php
        require_once "config.php";
    
        $json = array();
        $sqlQuery = "SELECT id, name AS title, dep_date AS start, ret_date AS end FROM jobs ORDER BY id";
    
        $result = mysqli_query($con, $sqlQuery);
        $eventArray = array();
        while ($row = mysqli_fetch_assoc($result)) {
            array_push($eventArray, $row);
        }
        mysqli_free_result($result);
    
        mysqli_close($con);
        echo json_encode($eventArray);
        ?>

    Thank you both so much for your help. Love your work. :)

  18. 5 hours ago, requinix said:

    What I would recommend is not abandoning this because you're having a small problem.

    Did you confirm that fetch-tours.php is executing and returning the correct data?

    Hi mate,

    Did a Var dump (I think) and this is what it showed:

    object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> array(1) { [0]=> int(1) } ["num_rows"]=> int(1) ["type"]=> int(0) }

     

  19. 5 minutes ago, requinix said:

    Seems alright, but there are 5 versions of FullCalendar and I don't know which one you're using.

    Check the browser's error console for any messages, and use its request monitoring tools to make sure that your fetch-tours.php really is being called and returning the data you think it is.

    Hi mate,

    Nothing in console. Just a few things with datatables, which I am aware of.

    Is there an alternative calendar script that I can use that you would recommend?

    Thanks for your help.

  20. 20 minutes ago, requinix said:
        $title = isset($row['name']);
        $start = isset($row['dep_date']);
        $end = isset($row['ret_date']);

    Are you sure that's what you want to do with those variables?

    I have changed that now.

    All I want to do is display the name, start date and finish date in the calendar.

    $data = array();
    $query = "SELECT * FROM tours ORDER BY id";
    $statement = $con->prepare($query);
    $statement->execute();
    $result = $statement->fetchAll();
    foreach ($result as $row) {
        $data[] = array(
            'id' => $row["id"],
            'title' => $row["name"],
            'start' => $row["dep_date"],
            'end' => $row['ret_date']
        );
    }
    echo json_encode($data);

    I have never used calendars before and am clueless with Javascript etc so any help with this would be appreciated.

  21. Hi guys,

    I am trying to display tour  information in fullcalendar but nothing is happening and no errors.

    Here is the php code from fetch-tours.php

    <?php
        require_once "config.php";
    
        $json = array();
        $sqlQuery = "SELECT * FROM jobs ORDER BY id";
    
        $result = mysqli_query($con, $sqlQuery);
        $eventArray = array();
        while ($row = mysqli_fetch_assoc($result)) {
        $title = isset($row['name']);
        $start = isset($row['dep_date']);
        $end = isset($row['ret_date']);
        $eventsArray['title'] = $title;
        $eventsArray['start'] = $start;
        $eventsArray['end'] = $end;
            array_push($eventArray, $row);
        }
        mysqli_free_result($result);
    
        mysqli_close($con);
        echo json_encode($eventArray);
        ?>

    And here is the Javascript that displays the calendar:

    <script type="text/javascript">
        $(document).ready(function() {
            var date = new Date();
            var d = date.getDate();
            var m = date.getMonth();
            var y = date.getFullYear();
    
            $('#calendar').fullCalendar(
            {
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,basicWeek,basicDay'
                },
                editable :true,
                events: "includes/fetch-tours.php",
            });
        })
    </script>

    The calendar displays fine but just no data.

    Any help is greatly appreciated.

    Cheers,

    Dan

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.