【问题标题】:How to plot data of by selecting diffrent patient_id from my database and plot graph on it?如何通过从我的数据库中选择不同的 patient_id 并在其上绘制图表来绘制数据?
【发布时间】:2019-03-27 17:56:13
【问题描述】:

我是这方面的初学者。

如果我在下拉选择中插入 P001(patient_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,它应该绘制第二位患者的图表,截至目前,它仅在第一列数据上显示图表。 如果我选择其他患者,我想在哪里调用该数据并绘制图表。

【问题讨论】:

    标签: php html mysql phpmyadmin


    【解决方案1】:

    我可以看到,当您选择 患者 ID 时,您并未将其发布到后端 php,因此 没有传入 sql 查询。

    工作轮次:

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

     if(isset($result)){
     $res = mysqli_query($link, "select * from heart_reating  limit 1");
     }
    

    您需要直接使用数据库中不同的 patient_id 值对其进行测试,以确保其正常工作 为了测试 patient_id of 1,它变成了

      $res = mysqli_query($link, "select * from heart_reating where patient_id= 1");
    

    现在将 patient_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,它仍然只显示数据库中的第一个专利图,即使在下拉列表中它也会重定向到第一个条目。
    • 您能否回显/打印 Patient_id 并告诉我您每次从下拉列表中选择患者 ID 时所拥有的信息,例如 echo $patient_id= $_POST['patient_id']
    • 我已经尝试过这些它的打印 (P001),即如果我选择它下面的患者 ID。但在下拉其恢复到 p002
    • 等等!。你是用ajax发送的吗?
    • 这行代码你替换了吗 $res = mysqli_query($link, "select * from heart_reating limit 1");
    猜你喜欢
    • 2019-12-12
    • 2013-10-25
    • 1970-01-01
    • 2015-02-07
    • 2016-01-23
    • 1970-01-01
    • 2016-04-19
    • 1970-01-01
    • 2021-07-24
    相关资源
    最近更新 更多