我想創建一個基本的時間段預約系統。但我遇到了一些問題。我的時間段沒有預定
我已經創建了一個日曆,我可以看到,有事情發生在上特有日期:
它從我的數據庫表中的信息。我正在使用PHPMyAdmin,並且在那裏手動添加了日期。
正如你可以在表中看到的,我也想用一個開始時間和結束時間。
如果我點擊我的日曆日期,創建這樣的附加事件鏈接:
<?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)) {
}
}
?>
點擊這使得我的網址看看服用點是這樣的:test.php%20.%20?month=04&day=18&year=2014&v=true&f=true#
我包括我的整個test.php的文件:
<?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>";
?>
正如你所看到的,我試圖顯示我的時隙:$sql = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'AND timestart >= $timearrays AND endtime <= $timearrays;";
我認爲我可以從URL中正確獲取日期,但我沒有看到給定日期的任何保留。
我希望,你們當中有些人可以幫助我。請問,如果我需要提供更多我的代碼。
或者如果任何人有更好的想法如何做到這一點,請分享。
我不確定是否應該節省時間。我基本上只是想要點擊「保留」,然後扭轉特定的時間段。所以也許開始和結束時間不是必須的?
啊。謝謝! :)我打印出sql,並得到這個:SELECT * FROM calendar WHERE eventDate = '04/18/2014'and timestart> = 8 AND endtime <= 8; 因此,我意識到結束和開始時間需要在我的數據庫中相同。 – Adnaves