Error while backing up the system registry, PHP interleaving

I am currently trying to create a booking engine to look something like this (easy to do in HTML and a little PHP)

enter image description here

After applying the script function and function, I get this:

enter image description here

code:

function displayCalendar(){
    global $database;
    global $smarty;
    $sID = $_GET['serverid'];
    $database->query('SELECT * FROM bookings WHERE sID = :server');
    $database->bind(':server',$sID);
    $getServer = $database->fetchAll();
    $week = $_GET['week'];

    $times = array();
    for ($h = 6; $h < 18; $h++){
        for ($m = 0; $m < 60 ; $m += 60){
            $time = sprintf('%02d:%02d', $h, $m);
            $times["'$time'"] = "$time";
        }
    }

    $days = array(
        'Monday',
        'Tuesday',
        'Wednesday',
        'Thursday',
        'Friday',
        'Saturday',
        'Sunday',
    );

    echo '<tr>';
    for ($i = 0; $i <= 6; $i++) {
        echo '<th>'.$days[$i].'</th>';
    }
    echo '</tr>';

    foreach ($times as $time)
    {
        echo '<tr>';
        for($i = 0; $i <= 6; $i++) {
            foreach($getServer as $test => $row){
                if($row['time'] == $time && $row['day'] == $days[$i] && $row['week'] == $week)
                {
                    echo '<td><button type="submit" class="btn btn-danger" aria-label="Left Align">'.$row['time'].'</button></td>';
                }
                else
                {
                    echo '<td><button type="submit" class="btn btn-success" aria-label="Left Align"><a href="?page=booking&serverid='.$sID.'&week='.$week.'&day='.$days[$i].'&time='.$time.'">'.$time.'</a></button></td>';
                }
            }
        }
        echo '</tr>';
    }
} 

      

+3


source to share


1 answer


I modified your code a bit, but got it to make it work.

The key is the function hasData()

that loops, and if the data is found, it returns a result that breaks the loop.



Your code continued in a loop that repeated with each iteration.

function getData(){
    global $database;
    $sID = $_GET['serverid'];
    $database->query('SELECT * FROM bookings WHERE sID = :server');
    $database->bind(':server',$sID);
    $getServer = $database->fetchAll();

    return $getServer;
}


function hasData($getServer, $time, $day, $week, $sID){
    foreach($getServer as $row){
        if($row['time'] == $time && $row['day'] == $day && $row['week'] == $week)
        {
            return '<td><button type="submit" class="btn btn-danger" aria-label="Left Align">'.$time.'</button></td>';
            break;
        }
    }
    return '<td><button type="submit" class="btn btn-success" aria-label="Left Align"><a href="?page=booking&serverid='.$sID.'&week='.$week.'&day='.$day.'&time='.$time.'">'.$time.'</a></button></td>';
}

function displayCalendar(){
    global $database, $smarty;
    $sID = $_GET['serverid'];
    $getServer = getData();

    $week = $_GET['week'];

    $times = array();
    for ($h = 6; $h < 18; $h++){
        for ($m = 0; $m < 60 ; $m += 60){
            $time = sprintf('%02d:%02d', $h, $m);
            $times["'$time'"] = "$time";
        }
    }

    $days = array(
        'Monday',
        'Tuesday',
        'Wednesday',
        'Thursday',
        'Friday',
        'Saturday',
        'Sunday',
    );

    echo '<tr>';
    for ($i = 0; $i <= 6; $i++) {
        echo '<th>'.$days[$i].'</th>';
    }
    echo '</tr>';

    foreach ($times as $time)
    {
        echo '<tr class="time">';
        for($i = 0; $i <= 6; $i++) {
            echo hasData($getServer, $time, $days[$i], $week, $sID);
        }
        echo '</tr>';
    }
} 

      

+1


source







All Articles