0

能否请一些人帮助解释/编辑此代码以确定为什么没有显示医生 ID。它是来自另一个表的 SQL 连接。显示约会日期和约会时间的第一个 SELECT 语句确实有效,但第二个 SELECT 语句 Doctor_id 不显示医生信息。

<!DOCTYPE html>
<?php
session_start();
?>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <title>
        </title>
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <link rel="stylesheet" href="my.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
        </script>
        <script src="my.js">
        </script>
        <!-- User-generated css -->
        <style>
        </style>
        <!-- User-generated js -->
        <script>
            try {

    $(function() {

    });

  } catch (error) {
    console.error("Your javascript has an error: " + error);
  }
        </script>
     </head>
    <body>
        <!-- Home -->
        <div data-role="page" id="page1">
            <div data-theme="a" data-role="header">
            <a data-role="button" data-theme="d" href="login.html" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                    Back
                </a>
                <a data-role="button" href="index.html" data-icon="home" data-iconpos="right" data-theme="d"class="ui-btn-right">
                 Home  
                </a>
                <h3>
                    Book appointment
                </h3>
           </div>

           <div data-role="content">
                <h3>
                    Select date/time:
                </h3>
                <br />
     <?php
{
    mysql_connect("localhost" , "" , "") or die (mysql_error());
    mysql_select_db("") or die(mysql_error());


    $pid=intval($_SESSION["Patient_id"]); $query = "SELECT Appointment_id, Doctor_id, Patient_id, Appointment_time, Appointment_date FROM Appointment where Patient_id=$pid";
    SELECT * Doctor_id
    FROM Appointment
    JOIN Doctor
    ON Appointment.Doctor_id=Doctor.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_id'] = $row['Doctor_id'];

    }
}
?>  

        <strong>Dates available</strong>            
        <select id="Availability" name="Availability">                      
        <option value="0">--Select date--</option>
        <option value="1"><?php echo $_SESSION['Appointment_date'];?></option>
        </select>

        <br />
        <br />

        <strong>Times available</strong>            
        <select id="Availability" name="Availability">                      
        <option value="0">--Select time--</option>
        <option value="2"><?php echo $_SESSION['Appointment_time'];?></option>>
        </select>

        <strong>Times available</strong>            
        <select id="Availability" name="Availability">                      
        <option value="0">--Select time--</option>
        <option value="2"><?php echo $_SESSION['Doctor_id'];?></option>>
        </select>

        <br />
        <br />

                <label for="textarea1">
                Message GP
                </label>
                <textarea name="" id="textarea1" placeholder="">
                </textarea>


             </div>
        </div>
    </body>
</html>

谢谢!

4

1 回答 1

1

为了使表格更易于编写,请在表格上添加别名,

SELECT a.*, b.Doctor_id
FROM   Appointment a
       INNER JOIN Doctor b
          ON a.Doctor_id = b.Doctor_id

要进一步了解有关联接的更多信息,请访问以下链接:

于 2013-03-31T06:02:22.000 回答