I am looking for assistance as I'm trying to create a testing booking system but each person needs to be booked onto a specific machine (laptop) at a specific time. Please see below database:
Apologies for the poor image but hopefully you get the idea. I've got the database to show me booked records, but I want to be able to see whats left.
I currently have 10 machines each with three time slots which is easier you visualise like this:
****************************************************************
* Machine/Laptop * Time Slot * Name * Test *
****************************************************************
* * 09:30 - 11:00 * John Adams * English *
* Laptop 1 * 11:00 - 13:00 * Book Slot * Free *
* * 13:00 - 14:00 * Raj Patel * English *
****************************************************************
* * 09:00 - 12:00 * Joe King * English *
* Laptop 2 * 11:00 - 13:00 * Andrew Lil * Maths *
* * 13:00 - 12:00 * Book Slot * Free *
****************************************************************
Now I don't know how to make a single database query work, but for example purposes heres a really dirty way to do it which would involve checking the database 30 times each time the page is loaded:
$sql = $dbconn->prepare('SELECT COUNT(*) AS `total`
FROM event_booking
INNER JOIN event_machine
ON event_booking.machine_id=event_machine.id
INNER JOIN event_machine_time
ON event_booking.machine_time_id=event_machine_time.id
WHERE information_id = '.$_GET["id"].' AND event_machine.id=1 AND event_machine_time.id=2');
$sql->execute();
$result = $sql->fetchObject();
if ($result->total > 0) { echo 'Slot Booked'; } else { echo '<a href="booking.php">Book Slot</a>'; }
For each time this is called I would have to change the event_machine.id=? AND event_machine_time.id=?
to call the specific slot.
I'm sure I'm approaching this wrong so any help would be great :)
EDIT:
If it helps heres what I'm going for
As you can see the purple buttons are the active slots and the darker one are booked. For a demo I could only fit 5 of the 10 laptops but you get the idea.
Here is the database query I'm using to call all of the event bookings. This shows all of the bookings made within the event from event_information
then I use fetchAll
into a table. But I don't know if something could be used with this query to get the booking ID's over to the time slots?
$Event_list = $dbconn->prepare('SELECT
event_booking.id,
event_booking.live,
event_booking.confirmation_email,
event_candidate.firstname,
event_candidate.surname,
event_candidate.email,
event_information.type,
event_machine.id AS machine_get_id,
event_machine.name,
event_machine_time.id AS machine_time_get_id,
event_machine_time.start_time AS machine_start_time,
event_machine_time.end_time AS machine_end_time
FROM event_booking
INNER JOIN event_candidate
ON event_booking.candidate_id=event_candidate.id
INNER JOIN event_information
ON event_booking.information_id=event_information.id
INNER JOIN event_machine
ON event_booking.machine_id=event_machine.id
INNER JOIN event_machine_time
ON event_booking.machine_time_id=event_machine_time.id
WHERE information_id = ?');
$Event_list->execute(array($_GET["id"]));
ANOTHER EDIT:
Another option would be to scrap the event_machine
and add a column called machine_name
into event_machine_time
then use the following:
$Event_Times = $dbconn->query('SELECT *
FROM event_machine_time
LEFT JOIN event_booking
ON event_machine_time.id=event_booking.machine_time_id
');
Use this within a table:
<td>
<?php foreach ($Event_Times->fetchAll() as $Event_Times_Row) { ?>
<?php if($Event_Times_Row["machine_name"] == "Laptop 1") { ?>
<a class="button<?php if($Event_Times_Row["information_id"] == $_GET["id"]) { echo " button-disabled"; } ?>" href="#"><?php echo date("G:i", strtotime($Event_Times_Row["start_time"])); ?></a>
<?php } } ?>
</td>
However I would need to call this 10 times and I don't think fetchAll
allows this and I would need to repeat this db query 10 times to make it work.