我有mysql table-activity,它有三列,即 - id,clientname,status;我只显示两列,即 - ,使用数据表的客户名和状态。
现在我想在数据库中更新我的clientname值,并在编辑时动态显示在我的数据表中。所以为此,我使用jeditable和datatable,但现在我不知道如何检索当前单元格的id和值,并通过jeditable将它们传递到我的php页面进行编辑。请帮助我。
提前致谢。 这是我迄今为止所尝试的 - Html代码 -
<tbody >
<?php
$sql= "SELECT * FROM `activity` ORDER BY clientname asc";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result))
{
$id = $row['id'];
$name = $row['clientname'];
echo "<tr id=".$row['id']."class='edit_tr'>";
echo $id;
echo " <td class='edit'>".$row['clientname']."</td>
<td>".$row['status']."</td>
</tr>";
}
?>
</tbody>
Jquery代码 -
<script>
$(document).ready(function() {
/* Init DataTables */
var oTable = $('#clientsheet').dataTable();
/* Apply the jEditable handlers to the table */
$('td', oTable.fnGetNodes()).editable( 'save.php', {
tooltip : 'Click cell to edit value...',
indicator : 'Saving...',
style : 'display:block;',
submit : 'OK',
cancel : 'Cancel',
data : " {'keyid':'id','keyname':'name'}",
type : 'select',
"Callback": function( sValue, x) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[1]);
/* Redraw the table from the new data on the server */
oTable.fnClearTable( 0 );
oTable.fnDraw();
},
"submitdata": function ( value, settings ) {
var aPos2 = oTable.fnGetPosition( this );
var id2 = oTable.fnGetData( aPos2[0] );
return {
"row_id": this.parentNode.getAttribute('id'),
"id2": id2[0],
"column": oTable.fnGetPosition( this )[ 2 ]
};
},
"height": "14px",
} );
} );
</script>
php code -
<?php
include('db.php');
$sql = "UPDATE `activity` SET clientname = '".$_POST['keyname']."' WHERE `id` = '".$_POST['id']."' ";
if($nameresult = $conn->query($sql)){
echo "successful";
}
else{
echo "failed";
}
?>
请帮帮我.. 提前致谢