doukao2180 2017-08-21 05:05
浏览 34

单个行控件在PHP中使用while循环填充表

I'm currently very stuck on this. I have a table that generates new rows as it loops through a datatable with a while loop. Within the while loop, i have some submit buttons that get re-created on each new row. My goal is to be able to individually control each row separately but I don't know how to accomplish this. So far, i have used a hidden to input the primary key of "id". After searching this site, i found a useful answer that showed me how to post the hidden id as a get variable and run my query with that. It works fine and updates the things I need it to, but it takes 2 page refreshes to do this. Also i had to remove the submit button and replace with a styled anchor tag to append the get variable to the url onclick. Is there anyway i can just leave my buttons or if not, accomplish the query update with only one page refresh instead of two? I'm updating only one field in the datatable. I tried to look into ajax but that's over my head. I'm open to any solution.

<?php
$con = mysql_connect("localhost","maximus1127","");
$db = mysql_select_db("patients",$con);
$get=mysql_query("SELECT patientName, brand, id FROM orders WHERE onOrder=1 and dispensed = 0");
$get2=mysql_query("SELECT patientName, brand FROM orders WHERE onOrder=0 and dispensed = 0");
 if(isset($_GET['deleteId'])) {
     include ("connection.php");
   $sql =  "UPDATE `orders` SET dispensed = 2 WHERE id = '".($_GET['deleteId'])."' LIMIT 1";
    mysqli_query($link, $sql);
 }
?>
<?php include ("header.php"); ?>
   <table class="table">
  <thead class="thead-inverse">
      <h3>On Order</h3>
    <tr>
      <th>Patient Name</th>
      <th>Brand</th>
      <th></th>
       <th></th>
       <th></th>
    </tr>
  </thead>
  <tbody>
        <td scope="row"><?php while ($row = mysql_fetch_array($get)) {
    //output a row here
    echo "<form> <tr><td>".($row['patientName'])."</td> <td>".($row['brand'])."</td><td class='hide'>".($row['id'])."</td><td><div class='btn-group-sm' role='group' aria-label='Basic example'>
  <a href='?deleteId=$row[id]' class='btn btn-danger' onclick= 'pageRefresh();'>Cancel</a>
    <input type='submit' class='btn btn-primary' name = 'view' value='View'>
  <input type='submit' class='btn btn-success' name = 'received' value='Received'>
</div>                                            </td></form>" ;
        }?>
        </td>
    </tr>
        </td>
    </tr>
  </tbody>
</table>
<table class="table">
  <thead class="thead-default">
      <h3>Received</h3>
    <tr>
      <th>Patient Name</th>
      <th>Brand</th>
      <th>Notified</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
   <tr>
        <td scope="row"><?php while ($row = mysql_fetch_array($get2)) {
    //output a row here
    echo "<form><tr><td>".($row['patientName'])."</td><td>".($row['brand'])."</td><td></td> 
   <td> <input type='submit' class=' btn btn-success' value='Dispense' /></td></form>";
   }?>
    </tr>
  </tbody>
</table>
<?php include("footer.php"); ?>
  • 写回答

1条回答 默认 最新

  • duanrang3357 2017-08-21 12:51
    关注

    First of all, you should fix your HTML. What you have shown us is not valid HTML. You cannot have a <tr> inside of a <td>... Also, you shouldn't need to have a form for each row, you could easily have one form for all your buttons. A form does append the value of the button that was used to submit it, you could use that to your advantage.

    <tbody>
        <?php 
            while ($row = mysql_fetch_array($get2)) {
                //output a row here
                echo "<tr><td>".($row['patientName'])."</td><td>".($row['brand'])."</td><td></td>";
                echo "<td><button type='submit' class='btn btn-success' name='dispense_id' value='".$row['id']."' />Dispense</button></td>";
            }
        ?>
    </tbody>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序