I have a web project there i am getting data from database and show them in a table/tables to edit and update the database. Table structure is same. There may be multiple tables or just only one table. It is a vary.
Each table row has a button to send updated data to the database. My problem is I cannot identify the button.Which button am i clicking. After i change the data i want to click the button and update that row in the database.
My code...
I am looping the section according to the field called agenda. Each agenda has a table. So there may be one agenda or multiple. Each table has a different ID. I increment table IDs.
<?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()
is the function of the button click.
For testing I tried with this but no luck. I just only want to get all the button clicked row values. I can do the update.
function row_update(){
var $row = $(this).closest("tr"); // Find the row
var $tds = $row.find("td");
$.each($tds, function() {
alert($(this).text());
});
}
I tried with this method also.
$("#responstable_tbl tr").click(function(){
});