-6

我有这个显示预订详细信息的 PHP 脚本。它工作正常并显示日期、时间、医生和房间。

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

        <strong>Dates available</strong>            
        <select id="Availability" name="Availability">                      
        <option value="0">--Select date--</option>
        <option value="3"><?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="3"><?php echo $_SESSION['Appointment_time'];?></option>>
        </select>

        <br />
        <br />

            <strong>Doctor Name</strong>            
        <select id="Availability" name="Availability">                      
        <option value="0">--Name--</option>
        <option value="2"><?php echo $_SESSION['Doctor_name'];?></option>>
        </select>

        <br />
        <br />

            <strong>Doctor Room</strong>            
        <select id="Availability" name="Availability">                      
        <option value="0">--Room--</option>
        <option value="2"><?php echo $_SESSION['Doctor_room'];?></option>>
        </select>

        <br />
        <br />

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

                <br />
                <br />

        <a data-role="button" data-theme="a" href="booked.php">
                    Book Appointment
                </a>  

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

我进入 phpmyadmin 并插入了另一个约会,以便用户可以选择,但这个约会不显示,只显示一个。有任何想法吗?

谢谢

4

1 回答 1

2

这实际上是一个有趣的错误

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

您将其设置为仅显示数据,$num==1但由于这些额外的原因,{}即使记录多于一个,它也会显示数据。因为该显示不在您的if块内,并且if对您的显示没有任何影响。但是您没有看到更多记录的原因是因为您只获取一次而不是循环

它必须像

while($row=mysql_fetch_assoc($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'];
}
于 2013-04-01T05:55:59.367 回答