【问题标题】:Removing data from database从数据库中删除数据
【发布时间】:2013-04-01 04:52:05
【问题描述】:

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

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

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

谢谢!

【问题讨论】:

  • 您使用哪个字段来标记是否预约......以及在哪个表格中,请更正您的第一行它应该是mysql_connect("localhost" , "" , "") or die (mysql_error());
  • mysql_* 扩展已被弃用,您应该使用PDOmysqli
  • 显示我的表Appointment 的sql结构

标签: php mysql join inner-join


【解决方案1】:

您应该在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-03
    • 2013-05-28
    • 2018-06-19
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 2015-07-01
    相关资源
    最近更新 更多