0

我需要使用内部连接显示另一个表中的数据。

$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
    INNER JOIN Doctor
    ON Appointment.Doctor_id=Doctor.Doctor_id

目前我有一个表中的数据显示,但我还需要使用内部连接显示另一个表中的数据。如何将创建的 SELECT 代码插入到我当前的编码中?医生详细信息是我尝试使用医生 ID 在我的页面中输出的内容。我是 php 新手。

谢谢

约会.php 的完整 php 代码

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

    }
}
?>  

        <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>

从第 57 行到第 98 行的完整代码

4

1 回答 1

0

我同意评论。试试这个(新的查询语法......)

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


$pid=intval($_SESSION["Patient_id"]); 
$query = "SELECT Apointment.Apointment_id, Apointment.Doctor_id, Apointment.Patient_id, Apointment.Time
          FROM (Doctor INNER JOIN Apointment ON Doctor.Doctor_id = Apointment.Doctor_id) INNER JOIN Patient ON Apointment.Patient_id = Patient.Patient_id
          WHERE Apointment.Patient_id='". $pid . "'";

//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'];

}
}
?>
于 2013-03-31T09:32:32.477 回答