2017-04-22 39 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在這裏 }); } 對不起,但我的英語不好。

相關問題