Php 如何通过从我的数据库中选择不同的患者id并在其上绘制图形来绘制的数据?

Php 如何通过从我的数据库中选择不同的患者id并在其上绘制图形来绘制的数据?,php,html,mysql,phpmyadmin,Php,Html,Mysql,Phpmyadmin,我是这方面的初学者 如果我在下拉选择中插入P001(患者id)数据,则它在下拉选择中使用P002,但从数据库中检索来自phpmyadmin的P001数据 <?php include "header.php"; include "connection.php"; ?> <form method="POST"> <div class="right_col" role="main"> <div class="">

我是这方面的初学者

如果我在下拉选择中插入P001(患者id)数据,则它在下拉选择中使用P002,但从数据库中检索来自phpmyadmin的P001数据

<?php
include "header.php";
include "connection.php";
?>
 <form  method="POST">
<div class="right_col" role="main">
            <div class="">
                <div class="page-title">
                    <div class="title_left">
                        <h3>Realtime Patient Health Monitor</h3>
                    </div>
                    <div class="title_right">
                        <div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
                            <div class="input-group">
                                <input type="text" class="form-control" placeholder="Search for...">
                    <span class="input-group-btn">
                      <button class="btn btn-default" type="button">Go!</button>
                    </span>
                            </div>
                        </div>
                    </div>
                </div>
                <!--FRONT ENDS-->
                <div class="clearfix"></div>
                <div class="row" style="min-height:500px">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">

                            <div class="x_content">
                               <label>Select Patient ID</label>
     <select class="form-control" name="patient_id">
         <?php 
         $result = mysqli_query($link,"SELECT patient_id from heart_reating");

         while($row = mysqli_fetch_array($result)) 
             echo "<option value='" . $row['patient_id'] . "'>" . $row['patient_id'] . "</option>";
         ?>
  </select>  

  <input  id="submit" type="submit" name="submit" value="submit"> 

                                <?php
                                 if(isset($result)){
                                         $res = mysqli_query($link, "select * from heart_reating  limit 1");
                                 }
                           // $res = mysqli_query($link, "select * from heart_reating ORDER BY id ASC LIMIT 1");
                         //   $res = mysqli_query($link, "SELECT DISTINCT patient_id, sdi, rate, temp, max, min, interv FROM heart_reating");
                           // echo "<table class='table table-bordered'>";
                            ?>
                            <col width=40>
                            <col width=50>
                            <col width=>
                            <col width=>
                            <col width=40>
                            <col width=40>
                            <col width=40>
                            <!--table properties close-->



                              <?php 
                                if(isset($_POST['submit'])){

                              while ($row = mysqli_fetch_array($res)) { ?>

                              <tr>

                              <div> 
                              <td >
                                  <iframe src="linegraph.html" height="620px" width="620px"></iframe>
                              </td>

                              <td><iframe src="new.html" height="620px" width="620px"></iframe></td>
                              </div>
                              <td><?php echo $row["max"] ?></td>
                              <td><?php echo $row["min"] ?></td>
                              <td><?php echo $row["interv"] ?></td>
                              </tr> 

                              <?php }}
                              ?>
  <!--<tr>
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
  </tr>-->  
                            </table>
                            <?php
                        /*    echo "<tr>";
                            echo "<th>";
                            echo "Patient ID";
                            echo "</th>";
                            echo "<th>";
                            echo "Sepses Detection Index(%)";
                            echo "</th>";
                            echo "<th>";
                            echo "Heart Rate";
                            echo "</th>";
                            echo "<th>";
                            echo "Temperature";
                            echo "</th>";
                            echo "<th>";
                            echo "Max";
                            echo "</th>";
                            echo "<th>";
                            echo "Interval";
                            echo "</th>";
                            echo "<th>";
                            echo "Min";
                            echo "</th>";
                            echo "</tr>";

                            //variable declaration closed
                            while ($row = mysqli_fetch_array($res)) {
                                echo "<tr>";
                                echo "<td>";
                        //        $pid = $row["patient_id"];
                                echo $row["patient_id"];
                                echo "</td>";
                                echo "<td>";
                                echo $row["sdi"];
                                echo "</td>";
                                echo "<td>";?>
                                <style>
                              .chart-container {
                                width: 640px;
                                height: 300px;
                              }
                                </style>  
                            <!--    <div class="chart-container"> --> 
                            <!--   <canvas id="mycanvas" width="300px" height="300px"></canvas> -->
   <canvas class="chart-container" id="mycanvas"></canvas>  
    </div>  
    <script type="text/javascript" src="js2/jquery.min.js">

    </script>
    <script type="text/javascript" src="js2/Chart.min.js">

    </script>
    <script type="text/javascript" src="js2/linegraph.js">

    </script> 
                                <?php
                                echo $row["rate"];
                                echo "<td>";
                                echo $row["temp"];
                                echo "</td>";
                                echo "<td>";
                                echo $row["max"];
                                echo "</td>";
                                echo "<td>";
                                echo $row["interv"];
                                echo "</td>";
                                echo "<td>";
                                echo $row["min"];
                                echo "</td>";
                                echo "</tr>";
                            }
                            echo "</table>"; */
                            ?>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
</div>
</div>
                              <script type="text/javascript" src="js2/jquery.min.js"></script>
                              <script type="text/javascript" src="js2/Chart.min.js"></script>
                              <script type="text/javascript" src="js2/linegraph.js"></script>
<?php
include "footer.php";
?>

实时患者健康监护仪
走!
选择患者ID

我可以看到,当您选择患者Id时,您没有将其发布到后端php,因此 未在sql查询中传递

工作循环:

寻找这一行代码,这就是您遇到问题的地方

 if(isset($result)){
 $res = mysqli_query($link, "select * from heart_reating  limit 1");
 }
您需要直接使用数据库中不同的患者id值对其进行测试,以确保其正常工作 要测试患者id为1的,它将变为

  $res = mysqli_query($link, "select * from heart_reating where patient_id= 1");
现在将患者id从表单传递到sql查询

$patient_id= $_POST['patient_id']
$res = mysqli_query($link, "select * from heart_reating where patient_id= '$patient_id'");
哦,是的,上面的代码仍然容易受到sql注入攻击,因此您需要使用一些函数来逃避它

mysqli_real_escape_string();
用法

$patient_id = mysqli_real_escape_string($con, $_POST['patient_id']);
其中,$con是数据库连接变量。您可以是$list或您已经实现的任何内容

更新部分

如果我理解正确的话。您可以使用php会话 在monitor.php中

您可以在php标记内启动如下会话

<?php

//start sessions
session_start();

//set patient id to session
$patient_id= $_POST['patient_id'];

$_SESSION['patient_id'] = $patient_id;


?>

data.php中

你可以这样做

<?php

//start sessions
session_start();
$pid = $_SESSION['patient_id'];
echo $pid

You can now use it in a query in data.php eg

mysqli_query($link, "select * from heart_reating where patient_id= '$pid'"); 

?>

但它仍然不能解决我的问题。它仍然只显示数据库中第一个病人的图形,即使在下拉列表中,如果我选择其他病人id,它将重定向到第一个条目。你能回显/打印病人id并告诉我每次从下拉列表中选择病人id时你都有什么吗,例如回显$patient\u id=$\u POST['patient\u id']我已经尝试过这些打印(P001)即,如果我选择,则在其下方显示患者id。但在下拉列表中,它将恢复为p002wait!。你是用ajax发送的吗?你是否替换了这行代码$res=mysqli\u query($link,“select*from heart\u reating limit 1”);