简体   繁体   中英

Booking scheme show available time between booked times in a single field

currently i'm showing only the booked times, but i'm now looking for a way to show the available times between the booked times. This is the markup i use.

                  $stmt = $pdo->prepare('SELECT * FROM bokningar WHERE frisor = :frisor AND datum = :datum ORDER BY datum, tid');  
                  $stmt->execute(array(
                    ':frisor' => $_GET['id'],
                    ':datum' => $dag
                  ));

                    while($row = $stmt->fetch()) {
                        echo goes here etc
                    }

For each $row there is a $row['tid'](start time) and $row['tid_slut](end time)

This is how i want it to look:

07:00-10:00
Available

10:00-12:00
Booked

12:00-13:20
Booked

13:20-14:50
Available

14:50-18:00
Booked

For example. How would i the most easiest way proceed with this?

Thanks in advance!

EDIT: forgot to add that the variables for start time(ex. 07:00): $arbetstider_idag[0] and end time: $arbetstider_idag[1]

Inside the loop store end time to a variable. In the next iteration compare current start time and stored end time. If the're different, time from end to start is free (because otherwise it would be at database), so echo time from last end to current start as available.

example:

  $start_time = $arbetstider_idag[0];
  $end_time = $arbetstider_idag[1];

   while($row = $stmt->fetch()) {

    if ($start_time != $row['tid'])
      echo "{$start_time}-{$row['tid']}<br>Available<br><br>";

    echo "{$row['tid']}-{$row['tid_slut']}<br>Booked<br><br>";

    $start_time = $row['tid_slut'];
  }

  if ($row['tid_slut'] != $end_time)
    echo "{$row['tid_slut']}-{$end_time}<br>Available<br><br>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM