0

我正在设计一个预订系统,我需要知道当另一个用户已经接受该约会时,您将如何从数据库中删除约会(因此不再显示)。

<?php
{
    mysql_connect("localhost" , "" , "" or die (mysql_error());
    mysql_select_db("") or die(mysql_error());


    $pid=intval($_SESSION["Patient_id"]); $query = "SELECT t1.*, t2.Doctor_name, t2.Doctor_room FROM Appointment AS t1 INNER JOIN Doctor AS t2 ON t1.Doctor_id=t2.Doctor_id";

    //executes query on the database
    $result = mysql_query ($query) or die ("didn't query");

    //this selects the results as rows
    $num = mysql_num_rows ($result);    

    //if there is only 1 result returned than the data is ok 
    if ($num == 1) {}
    {
        $row=mysql_fetch_array($result);
        $_SESSION['Appointment_date'] = $row['Appointment_date'];
        $_SESSION['Appointment_time'] = $row['Appointment_time'];
        $_SESSION['Doctor_name'] = $row['Doctor_name'];
        $_SESSION['Doctor_room'] = $row['Doctor_room'];
    }
}

上面的代码目前允许用户预约。如果已拍摄,我需要不显示时间和日期。

谢谢!

4

1 回答 1

0

您应该在表 Appointment 表中有一个布尔字段来将其标记为已使用或未使用.. 我假设它为'Appointment_taken...如果这是 0,那么约会仍然要进行..

然后你可以检查条件如下

            <?php
        {
            mysql_connect("localhost" , "" , "") or die (mysql_error());
            mysql_select_db("") or die(mysql_error());


            $pid=intval($_SESSION["Patient_id"]); 
            $query = "SELECT t1.*, t2.Doctor_name, t2.Doctor_room ".
                     "FROM Appointment AS t1 INNER JOIN Doctor AS t2 ".
                     "ON t1.Doctor_id=t2.Doctor_id";

            //executes query on the database
            $result = mysql_query ($query) or die ("didn't query");

            //this selects the results as rows
            $num = mysql_num_rows ($result);    

            //if there is only 1 result returned than the data is ok 
            if ($num == 1)
            {
                $row = mysql_fetch_array($result);

                if($row['Appointment_taken'] == 0 )
                {
                    $_SESSION['Appointment_date'] = $row['Appointment_date'];
                    $_SESSION['Appointment_time'] = $row['Appointment_time'];
                }

                $_SESSION['Doctor_name']      = $row['Doctor_name'];
                $_SESSION['Doctor_room']      = $row['Doctor_room'];
            }
        }

        ?>

正如其他人建议的那样,您应该开始学习 PDO 和 mysqli

于 2013-04-01T05:00:24.287 回答