Php jqgrid编辑单元格并保存到数据库
我正在使用jqgrid,试图编辑一个单元格并将值更新到数据库中的表中,但我遗漏了一些东西,无法使其工作。如果我遗漏了什么,请帮我更正。下面是代码供您参考。请帮忙。提前谢谢 HTMLPhp jqgrid编辑单元格并保存到数据库,php,jquery,jqgrid,Php,Jquery,Jqgrid,我正在使用jqgrid,试图编辑一个单元格并将值更新到数据库中的表中,但我遗漏了一些东西,无法使其工作。如果我遗漏了什么,请帮我更正。下面是代码供您参考。请帮忙。提前谢谢 HTML $qr="SELECT id,`emp_id`,`emp_name`, `att_date`, `emp_join_date`, `intime`,`outtime`,`Total_Hours`,`OT Hours`,`Status` FROM `db_emp_attendance` WHERE Status
$qr="SELECT id,`emp_id`,`emp_name`, `att_date`, `emp_join_date`, `intime`,`outtime`,`Total_Hours`,`OT Hours`,`Status` FROM `db_emp_attendance` WHERE Status='Absent' and att_date='2017-04-01'";
$q = mysql_query($qr);
$rows = array();
while($r = mysql_fetch_assoc($q)) {
$rows[] = $r;
}
$json_data=json_encode($rows);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/ecmascript" src="jquery.min.js"></script>
<script type="text/ecmascript" src="jquery.jqGrid.min.js"></script>
<script type="text/ecmascript" src="grid.locale-en.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="jquery-ui.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="ui.jqgrid.css"/>
<meta charset="utf-8" />
</head>
<body>
<table id="rowed5"></table>
<script type="text/javascript">
var lastsel2
jQuery("#rowed5").jqGrid({
datatype: "local",
height: 400,
autowidth: true,
colNames:['ID','Emp ID','Name', 'Join Date','Attendance Date', 'Time In','Time Out','Total Hours','OT Hours','Status','leave_type'],
colModel:[
{name:'id',index:'id', width:75,align:"center",key: true},
{name:'emp_id',index:'emp_id', width:75,align:"center"},
{name:'emp_name',index:'emp_name', width:150,align:"left"},
{name:'emp_join_date',index:'emp_join_date', width:150,align:"center"},
{name:'att_date',index:'att_date', width:100, align:"center"},
{name:'intime',index:'intime', width:80,align:"center"},
{name:'outtime',index:'outtime', width:80,align:"center"},
{name:'Total_Hours',index:'Total_Hours', width:80,align:"center"},
{name:'OT Hours',index:'OT Hours', width:80,align:"center"},
{name:'Status',index:'Status', width:150,align:"center"},
{name:'leave_type',index:'leave_type', width:150, sortable:false,editable: true,
edittype: "select",
editoptions: {
value: "SickLeave:SickLeave;DayOff:DayOff;Vacation:Vacation"}
}
],
onSelectRow: function(id){
if(id && id!==lastsel2){
jQuery('#rowed5').jqGrid('restoreRow',lastsel2);
jQuery('#rowed5').jqGrid('editRow',id,true);
lastsel2=id;
}
},
editurl:'update.php',
caption: "Attendance"
});
var mydata2 =<?PHP echo $json_data;?>;
for(var i=0;i < mydata2.length;i++)
jQuery("#rowed5").jqGrid('addRowData',mydata2[i].id,mydata2[i]);
</script>
</body>
</html>
if($_POST['oper']=='edit')
{
$id = mysql_real_escape_string($_POST['id']);
$leave_type = mysql_real_escape_string($_POST['leave_type']);
$sql = "UPDATE db_emp_attendance SET leave_type = '$leave_type' WHERE id = '$id'";
mysql_query($sql);
}
我找到了一个解决方案,现在它正在数据库中更新。我不得不添加cellEdit:true,cellsubmit:'remote',cellurl:'update.php'我找到了一个解决方案,现在它正在数据库中更新。我不得不添加cellEdit:true,cellsubmit:'remote',cellurl:'update.php'我找到了一个解决方案,现在它正在数据库中更新。我不得不添加
cellEdit:true,
cellurl:'update.php',
,现在我又遇到了一个问题,一旦编辑了单元格,值就会保存在数据库中,在重新加载网格后,值会消失,但在数据库中可用。重新加载后,如何显示已编辑单元格的DB值?请帮助。我找到了一个解决方案,现在它正在数据库中更新。我不得不添加cellEdit:true,
cellurl:'update.php',
,现在我又遇到了一个问题,一旦编辑了单元格,值就会保存在数据库中,在重新加载网格后,值会消失,但在数据库中可用。重新加载后,如何显示已编辑单元格的DB值?请帮忙。