2017-04-22 63 views
0

我有一个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

http://stackoverflow.com/questions/14460421/jquery-get-the-contents-of-a-table-row-with-a-button-click 这应该会帮助你获得行。 – blackandorangecat

+0

它的工作........ –

+0

所以耶? '111111111111111' – blackandorangecat

回答

0

您可以在函数row_update()中传递onclick函数中的行ID。 函数row_update(rowid){ Alert(rowid); 您的更新数据ID在这里 }); } 对不起,但我的英语不好。

相关问题