获取单击的按钮表行值以更新数据库

时间:2017-04-22 13:43:13

标签: php jquery html mysql

我有一个Web项目,我从数据库中获取数据并在表/表中显示它们以编辑和更新数据库。表结构相同。可能有多个表或只有一个表。这是一个变化。

每个表行都有一个按钮,用于将更新的数据发送到数据库。我的问题是我无法识别按钮。我点击了哪个按钮。在我更改数据后,我想单击按钮并更新数据库中的该行。

我的代码......

我根据名为议程的字段循环播放该部分。每个议程都有一张桌子。所以可能有一个议程或多个议程。每个表都有不同的ID。我增加了表ID。

<?php 

    $mCount = 0;
    while ($row = mysqli_fetch_assoc($agenda_result)) {
    $myCount = ++$mCount;

  ?>

  <section class="color">

      <h1 class="agenda_head"> <?php echo trim($row['agenda_name']); ?> </h1>

      <?php 

      $agnd_id = $row['agenda_id'];

      $get_tbl_data = $db->prepare("SELECT distinct mType, mDivision, discuss_point, mAction, statDate, dueDate, status, user_tbl.fName FROM meeting_i_tbl inner join user_tbl on meeting_i_tbl.responsible_id = user_tbl.user_id WHERE meeting_i_tbl.meeting_id = ? and meeting_i_tbl.agenda_id = ?");
      $get_tbl_data->bind_param("ss",$selected_meet_id,$agnd_id);
      $get_tbl_data->execute();
      $tbl_data_result = $get_tbl_data->get_result();    

      ?>

      <center><table class="responstable" id="responstable_tbl<?php echo $myCount; ?>" name="res_tbl_name<?php echo $myCount; ?>"> 
      <tr>
      <th>Type</th>
      <th>Division</th>
      <th>Discuss Points</th>
      <th>Action</th>
      <th>Start Date</th>
      <th>Due Date</th>
      <th>Status</th>
      <th>Res: Person</th>
      <th></th>
      </tr>

      <?php


      while ($row_res = mysqli_fetch_assoc($tbl_data_result)) {


      ?>

      <tr>
      <td> <?php echo trim($row_res['mType']); ?> </td>
      <td> <?php echo trim($row_res['mDivision']); ?> </td>
      <td> <?php echo trim($row_res['discuss_point']); ?> </td>
      <td> <?php echo trim($row_res['mAction']); ?> </td>
      <td><input type="text" class="datepickerClass" value="<?php echo trim($row_res['statDate']); ?>" placeholder="Meeting Date"/></td>
      <td><input type="text" class="datepickerClass" value="<?php echo trim($row_res['dueDate']); ?>" placeholder="Due Date"/></td>

      <td class="select_op_div">

      <select name="status" class="select_option">
        <option<?php if ($row_res['status'] == "1"): ?> id="1" selected="selected"<?php endif; ?>>Pending</option>
        <option<?php if ($row_res['status'] == "2"): ?> id="2" selected="selected"<?php endif; ?>>On Going</option>
        <option<?php if ($row_res['status'] == "3"): ?> id="3" selected="selected"<?php endif; ?>>Completed</option>
        <option<?php if ($row_res['status'] == "4"): ?> id="4" selected="selected"<?php endif; ?>>-</option>
      </select>

      </td>

      <td class="nr"> <?php echo trim($row_res['fName']); ?> </td>
      <td>
      <form action='detailform.php' method='POST'>
      <input type='submit' onclick="row_update()" name='btn_update' value='up'/>
      </form>
      </td>
      </tr>

      <?php

      }   

      ?>
      </table></center>

  </section>

<div style="height: 25px;">
</div>

<?php

}

mysqli_close($db);
$myCount = 0;
?>

row_update()是按钮点击的功能。

为了测试我试过这个但没有运气。我只是想获得所有按钮点击的行值。我可以做更新。

function row_update(){

var $row = $(this).closest("tr");    // Find the row
var $tds = $row.find("td");
$.each($tds, function() {
    alert($(this).text());
});

}

我也尝试过这种方法。

   $("#responstable_tbl tr").click(function(){

    });

1 个答案:

答案 0 :(得分:0)

您可以在onclick函数中传递行id,如函数row_update(); function row_update(rowid){ 警报(ROWID); 您的更新数据ID在此处 }); } 对不起,但我的英语不好。