Hello guys. I'm new to this Forum. So I hope that I'm posting in the right place.
Here's wats up:
I want to create a basic time slot booking system. But I've run into some problems.
I have created a calendar where I can see that something is happening on a speific date:
[ATTACH]5099[/ATTACH]
It takes the information from my database table:
[ATTACH]5101[/ATTACH]
But as you can see in the table, I would also like to use a start time and an endtime.
If I click a date, I create the add-event link like this:
[CODE]<?php
if (isset ( $_GET ['v'] )) {
echo "<a href='test.php . ?month=" . $month . "&day=" . $day . "&year=" . $year . "&v=true&f=true'>Add Event</a>";
if (isset ( $_GET ['f'] )) {
include ("test.php");
}
$sqlEvent = "SELECT * FROM calendar WHERE eventDate='" . $month . "/" . $day . "/" . $year . "'";
$resultEvents = mysqli_query ( $mysqli1, $sqlEvent );
echo "<br>";
while ( $events = mysqli_fetch_array ( $resultEvents ) ) {
}
}
?>[/CODE]
My test.php:
[CODE]<?php
$hostname = 'localhost';
$username = 'root';
$password = '';
$dbname = "calendar";
$error = 'Cannot connect to the database';
$mysqli1 = new mysqli ( $hostname, $username, $password, $dbname ) or die ( $error );
if (isset ( $_GET ['day'] )) {
$day = $_GET ['day'];
} else {
$day = date ( "j" );
}
if (isset ( $_GET ['month'] )) {
$month = $_GET ['month'];
} else {
$month = date ( "n" );
}
if (isset ( $_GET ['year'] )) {
$year = $_GET ['year'];
} else {
$year = date ( "Y" );
}
$dateToCompare = $month . '/' . $day . '/' . $year;
echo "<br/><br/><h3>Reservations</h3>";
$timearray = array(8,9,10,11,12,13,14,15,16,17,18,19,20,21,22);
$tablecolor = 1;
echo "<table style='width: 90%;'>";
echo "<tr>";
echo "<th>";
echo "Time";
echo "</th>";
echo "<th>";
echo "Status";
echo "</th>";
echo "</tr>";
foreach ($timearray as $timearrays) {
if($tablecolor %2 == 0) {
echo "<tr>";
}
else {
echo "<tr style='background-color: rgb(0,100,255); background: rgb(0,100,255);'>";
}
echo "<th>";
if ($timearrays == 8) {echo "<h3>8-9am</h3>";}
if ($timearrays == 9) {echo "<h3>9-10am</h3>";}
if ($timearrays == 10) {echo "<h3>10-11am</h3>";}
if ($timearrays == 11) {echo "<h3>11-12am</h3>";}
if ($timearrays == 12) {echo "<h3>12-13am</h3>";}
if ($timearrays == 13) {echo "<h3>13-14am</h3>";}
//Develop your timeslots here to display as required
echo "</th>";
echo "<td>";
$sql = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'AND timestart >= $timearrays AND endtime <= $timearrays;";
$result = mysqli_query($mysqli1,$sql);
if (mysqli_num_rows($result) == 0) {
echo "<a href='#'><h3 style='color: rgb(255,0,0);'>Reserve</h3></a>";
} else {
echo "<h3>Not Available, taken by someone</h3>";
while($row = mysql_fetch_array($result)) {
echo "<br />";
}
}
echo "</td>";
echo "</tr>";
$tablecolor++;
}
echo "</table>";
?>[/CODE]
As you can see, I try to display my timeslots:
`$sql = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'AND timestart >= $timearrays AND endtime <= $timearrays;";`
I think that I get my dates correctly from the URL, but I don't see any reservations for a given date.
[ATTACH]5103[/ATTACH]
I hope that some of you can help me out. And please ask, if I need to provide more of my code.
event2.png
event.png
event3.png