从数据库中删除数据

时间:2013-04-01 04:52:06

标签: php mysql join inner-join

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

<?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'];
    }
}

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

谢谢!

1 个答案:

答案 0 :(得分: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