【问题标题】:My time slots are not booked我的时间段没有被预订
【发布时间】:2014-05-28 06:45:24
【问题描述】:

我想创建一个基本的时段预订系统。但是我遇到了一些问题。

我创建了一个日历,我可以在其中看到特定日期发生的事情:

它从我的数据库表中获取信息。我正在使用 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&amp;day=18&amp;year=2014&amp;v=true&amp;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 &gt;= $timearrays AND endtime &lt;= $timearrays;";

我认为我从 URL 中正确获取了我的日期,但我没有看到给定日期的任何预订。

我希望你们中的一些人可以帮助我。如果我需要提供更多代码,请询问。

或者如果有人对如何做到这一点有更好的想法,请分享。

我不确定我是否应该注意时间。我基本上只是希望能够单击“保留”然后反转该特定时间段。所以也许开始和结束时间不是必需的?

【问题讨论】:

    标签: php sql mysqli


    【解决方案1】:

    尝试调试您的应用程序。但我想问题可能是您创建的查询中的$timearrays。我不认为(尚未测试)它是这样工作的。

    我的建议,在初始化之后打印出$sql,看看它会返回什么。然后打开 PHPmyadmin(从你的数据来看,我猜你正在使用它)并查看它在那里返回的内容。

    【讨论】:

    • 啊。谢谢! :) 我打印出 sql,得到了这个: SELECT * FROM calendar WHERE eventDate='04/18/2014'AND timestart >= 8 AND endtime
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多