search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

changing court name

Related article: HTML5 Tennis Court Reservation (PHP, JavaScript)
Asked by Ryan
6 years ago.

Hi there just enquirying about how to change the name of the courts i.e court 1---pitch 1

Answer posted by Dan Letecky [DayPilot]
6 years ago.

At this moment the tutorial project doesn't include the user interface to change the court names. You'd have to add it or you can also modify the database directly.

The sample SQLite database is generated automatically if daypilot.sqlite file is not found. It's initialized using the code in _db.php:

<?php

date_default_timezone_set("UTC");

$db_exists = file_exists("daypilot.sqlite");

$db = new PDO('sqlite:daypilot.sqlite');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

if (!$db_exists) {
    //create the database
    $db->exec("CREATE TABLE IF NOT EXISTS events (
        id INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL, 
        name TEXT, 
        start DATETIME, 
        end DATETIME,
        resource_id VARCHAR(30))");
    
    $db->exec("CREATE TABLE [groups] (
        [id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
        [name] VARCHAR(200)  NULL)");
    
    $db->exec("CREATE TABLE [resources] (
        [id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
        [name] VARCHAR(200)  NULL,
        [group_id] INTEGER  NULL)");

    $items = array(
        array('id' => '1', 'name' => 'Indoor'),
        array('id' => '2', 'name' => 'Outdoor'),        
    );
    $insert = "INSERT INTO [groups] (id, name) VALUES (:id, :name)";
    $stmt = $db->prepare($insert);
    $stmt->bindParam(':id', $id);
    $stmt->bindParam(':name', $name);
    foreach ($items as $m) {
      $id = $m['id'];
      $name = $m['name'];
      $stmt->execute();
    }

    $items = array(
        array('group_id' => '1', 'name' => 'Court 1'),
        array('group_id' => '1', 'name' => 'Court 2'),
        array('group_id' => '1', 'name' => 'Court 3'),
        array('group_id' => '1', 'name' => 'Court 4'),
        array('group_id' => '2', 'name' => 'Court 5'),        
        array('group_id' => '2', 'name' => 'Court 6'),        
        array('group_id' => '2', 'name' => 'Court 7'),        
        array('group_id' => '2', 'name' => 'Court 8'),        
    );
    $insert = "INSERT INTO [resources] (group_id, name) VALUES (:group_id, :name)";
    $stmt = $db->prepare($insert);
    $stmt->bindParam(':group_id', $group_id);
    $stmt->bindParam(':name', $name);
    foreach ($items as $m) {
      $group_id = $m['group_id'];
      $name = $m['name'];
      $stmt->execute();
    }

}

?>

If you just want a testing database with different names you can update _db.php as needed, delete daypilot.sqlite file and run the application - it will generate a new database with the updated details.

Comment posted by Ryan
6 years ago.

Hi there thank you for the response.

I have changed my code to this however it is only displaying "Pitch 1" at the bottom of the indoor section.

Any advice on what might be the issue

Thanks again

<?php

date_default_timezone_set("UTC");

$db_exists = file_exists("daypilot.sqlite");

$db = new PDO('sqlite:daypilot.sqlite');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

if (!$db_exists) {
//create the database
$db->exec("CREATE TABLE IF NOT EXISTS events (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT,
start DATETIME,
end DATETIME,
resource_id VARCHAR(30))");

$db->exec("CREATE TABLE [groups] (
[id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
[name] VARCHAR(200) NULL)");

$db->exec("CREATE TABLE [resources] (
[id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
[name] VARCHAR(200) NULL,
[group_id] INTEGER NULL)");

$items = array(
array('id' => '1', 'name' => 'Indoor'),
array('id' => '2', 'name' => 'Outdoor'),
);
$insert = "INSERT INTO [groups] (id, name) VALUES (:id, :name)";
$stmt = $db->prepare($insert);
$stmt->bindParam(':id', $id);
$stmt->bindParam(':name', $name);
foreach ($items as $m) {
$id = $m['id'];
$name = $m['name'];
$stmt->execute();
}

$items = array(
array('group_id' => '1', 'name' => 'Pitch 1'),
array('group_id' => '1', 'name' => 'Pitch 2'),
array('group_id' => '1', 'name' => 'Pitch 3'),
array('group_id' => '1', 'name' => 'Pitch 4'),
array('group_id' => '2', 'name' => 'Room 1'),
array('group_id' => '2', 'name' => 'Room 2'),
array('group_id' => '2', 'name' => 'Room 3'),
array('group_id' => '2', 'name' => 'Room 4'),
);
$insert = "INSERT INTO [resources] (group_id, name) VALUES (:group_id, :name)";
$stmt = $db->prepare($insert);
$stmt->bindParam(':group_id', $group_id);
$stmt->bindParam(':name', $name);
foreach ($items as $m) {
$group_id = $m['group_id'];
$name = $m['name'];
$stmt->execute();
}

}

?>

Comment posted by Ryan
6 years ago.

Hi there im also wondering where the data is going for the bookings. Can i extract the data ?

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.