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:
It takes the information from my database table. I'm using PHPMyAdmin, and I've added the date manually in there.
As you can see in the table, I would also like to use a start time and an endtime.
If I click a date in my calendar, I create the add-event link like this:
<?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 ) ) {
}
}
?>
Clicking this makes my url look somehting like this: test.php%20.%20?month=04&day=18&year=2014&v=true&f=true#
I've included my whole test.php file:
<?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>";
?>
As you can see, I try to display my timeslots: $sql = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'AND timestart >= $timearrays AND endtime <= $timearrays;";
$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.
I hope that some of you can help me out. And please ask, if I need to provide more of my code.
Or if anyone has a better idea on how to do this, please share.
I'm not really sure if I should be conserned about time. I basically just want the ability to click on "Reserve" and then reverse that specific time slot. So maybe a start and an end time isn't nessary?
Try to debug your application. But I guess the problem will probably be the $timearrays
in the query you create. I don't think (haven't tested) it works that way.
My suggestion, print out $sql
after you've initialized it and see what it returns. Then open PHPmyadmin (which I guess you're using, by the looks of your data) and see what it returns there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.