I am having problems with my query and wondered if anyone has any advice to where I'm going wrong. I have a time slot booking system for testing machines in my company
I have two tables, one called event_machine_time
that handles the machine names and timings and the other event_bookings
that handles the booking
event_machine_time // Table Name
id
machine_name // Laptop Name e.g. Laptop 1
start_time // Start Time
end_time // End Time
Each 'machine_name' is added three times, one for each of the time slots:
**********************************************
* id * machine_name * start_time * end_time *
**********************************************
* 1 * Laptop 1 * 09:30:00 * 11:00:00 *
* 2 * Laptop 1 * 11:30:00 * 13:00:00 *
* 3 * Laptop 1 * 13:30:00 * 15:00:00 *
* 4 * Laptop 2 * 09:30:00 * 11:00:00 *
* 5 * Laptop 2 * 11:30:00 * 13:00:00 *
* 6 * Laptop 2 * 13:30:00 * 15:00:00 *
**********************************************
This then is then linked to the 'event_booking' via a row called machine_id
table which holds all the booking data. The key part to where I am going wrong is in the information_id
as I must be calling it wrong!
I want to call all the machine_name
rows but check if there is a match on event_booking
on both machine_id
and information_id
so I can disable to booking link.
Here is my current code:
$Event_Times = $dbconn->query('SELECT
event_machine_time.machine_name,
event_machine_time.start_time,
event_machine_time.id AS machine_id,
event_booking.information_id
FROM event_machine_time
LEFT JOIN event_booking
ON event_machine_time.id=event_booking.machine_time_id
WHERE event_booking.information_id = '.$_GET["id"].' OR event_booking.information_id IS NULL
ORDER BY start_time
');
$Event_Times_Loop = $Event_Times->fetchAll(PDO::FETCH_ASSOC);
I don't normally use $_GET["id"] directly in a SQL but I used it as a quick example as this is how the page knows what the event date is.
One of the 7 loops:
<td>
<?php foreach ($Event_Times_Loop as $Event_Times_Row) { ?>
<?php if($Event_Times_Row["machine_name"] == "Laptop 1") { ?>
<a data-title="Book <?php echo date("G:i", strtotime($Event_Times_Row["start_time"])); ?> slot?" class="button<?php if($Event_Times_Row["information_id"] == $_GET["id"]) { echo " button-disabled"; } ?> msg_testing_booking" href="make_booking.php?<?php echo "i_id=".$Event_Data_ID."&m_id=".$Event_Times_Row["machine_id"].""; ?>"><?php echo date("G:i", strtotime($Event_Times_Row["start_time"])); ?></a>
<?php } } ?>
</td>
So from the code above if a record is found to match in event_booking
it disables the button but it appears to output differently on each testing day
I can see the relationship where its only showing free slots from the other page, but now its hiding the other slots as its behaving as if there booked, but for some reason hiding them.
Its just a bit beyond my knowledge and any help would be amazing!