【问题标题】:inserting data depending on a ROW根据 ROW 插入数据
【发布时间】:2019-07-13 11:15:36
【问题描述】:

我正在尝试更新 phpmyadmin 上的表格。状态栏应该根据谁的 id 雕像被更新而更新。

这是第一个检查雕像的代码。如果雕像被更新,该按钮将被禁用。否则,按钮将被启用:

<div class = "table-responsive">
<form action= "e.php" method="post">
<table class="table">

<thead>
  <tr class="active">
    <!--<td><input type="checkbox" id = "chckHead" /> Select</td>-->
    <td>Patient Name</td>
    <td>Patient ID</td>
    <td>Medicin</td>
    <td>DONE</td>
    <td>Male Side</td>


  </tr>
</thead>

<tbody>

  <?php 
 $sql="SELECT * from medicin_refill";   
 $result = mysqli_query($dbhandle,$sql);
 while( $row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
     $id=$row['id'];
    Print ("<tr class='warning'>");
    //print("<td><input type='checkbox' class = 'chcktbl' id='ch' /></d>");
    print("<td>".$id."</td>");
    print("<td>".$row['pname']."</td>");
    print("<td>".$row['medicin']."</td>");
    if ($row['status']== "DONE" or $row['status']=="Male Side"){
        print("<td><button name='button1' id='button1' class='btn btn-secondry btn-sm btn-block' disabled>Updated</button></td>");
        print("<td><button name='button1' id='button1' class='btn btn-secondry btn-sm btn-block' disabled>Updated</button></td>");}


    else{
         print("<td><button name='button1' id='button1' class='btn btn-danger' >DONE</button></td>");
         print("<td><button name='button2' id='button2' class='btn btn-danger' >Male Side</button></td>");}
 }

    ?>

在我将放置的其他代码中,雕像将被更新。但我的问题是所有行的数据都在更新,不仅是指定的行:

$sql = "SELECT id FROM logph WHERE id = '$login_session1'";
          $result = mysqli_query($dbhandle,$sql);
$sql1="SELECT id from medicin_refill";
            $result1 = mysqli_query($dbhandle,$sql1);
            $id= $row['id'];


    if (isset($_POST['button1'])) {
        $result = mysqli_query($dbhandle,$query);
    mysqli_query($dbhandle,"UPDATE medicin_refill SET status='DONE' where id ='$id'") or die(mysqli_error($dbhandle));}

    else if (isset($_POST['button2'])) {
        $result = mysqli_query($dbhandle,$query);
    mysqli_query($dbhandle,"UPDATE medicin_refill SET status='Male Side'") or die(mysqli_error($dbhandle));}

    header("Location:employee page loged.php");

我的问题是如何更新特定行的雕像而不更新整行的雕像? 提前谢谢你!

【问题讨论】:

  • 我实际上没有看到问题/
  • 我编辑了问题
  • 我没有看到表单,您如何处理按钮触发器?它是您进行查询时需要传递的 ID UPDATE medicin_refill SET status='DONE' WHERE id=XXX
  • 第一个表单将数据发送到第二个代码
  • 代码中没有表格,这里不能读心。

标签: php mysql mysqli phpmyadmin


【解决方案1】:

我在您编辑问题之前写了这个,我不认为来自

的 id

SELECT id FROM logph WHERE id = '$login_session1'

是您想要的 id,所以..在第一个 while 块中,我们需要 id,以便在表单提交中过去。有几种方法,但让我们将其作为值添加到按钮

为每个按钮添加

value='".$id."'

那么 $id 将是 e.php 中的 $_POST['id'] ,这是要在更新中使用的值

【讨论】:

    猜你喜欢
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多