JQGrid,如何将JSON字符串发布到PHP来处理并发送到数据库?

好的,我有多个想要发送到数据库onclick的行。 创建他们发布的选定数据行和firebug节目的字符串。 但是我不能把它发布到php并作为新条目发送到数据库。 请帮忙。我也想在发送到不同的表后从数据库中删除行。 请我帮助生死。

jqgrid [edit]最后把它发布到数据库中。 唯一的问题是它每次选择发布7次。 我希望它只为每个选择发布一个。 有什么帮助吗?

$(function(){ $("#list").jqGrid({ url:'request.php', editurl: "sendyo.php", datatype: 'xml', mtype: 'GET', multiselect:true, multiboxonly:true, height: 450, width: 850, colNames:['id','Project', 'Assigned To','Assign Date','Check Date','Due Date','Attachments'], colModel :[ {name:'id', index:'id', width:25}, {name:'name', index:'name', width:250, align:'left',editable:true, editoptions:{ size:60} }, {name:'id_continent', index:'id_continent', width:55, align:'right',editable:true,edittype:'select', editoptions:{value: "Henry:Henry; Ramon:Ramon; Paul:Paul" },mtype:'POST' }, {name:'lastvisit', index:'lastvisit', width:70, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'md-Y',editable:true, edittype: 'text',mtype:'POST' ,editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'m/d/yy'});}}} , {name:'cdate', index:'cdate', width:70, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'md-Y', edittype: 'text',editable:true ,mtype:'POST' ,editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'m/d/yy'});}}} , {name:'ddate', index:'ddate', width:70, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'md-Y',date:'true',editable:true, edittype: 'text',editoptions:{size:10, dataInit:function(elem){$(elem).datepicker({dateFormat:'m/d/yy'});}}} , {name:'email', index:'email', width:70,align:'center',sortable:false,mtype:'POST' } ], pager: '#pager', rowNum:20, rowList:[20,40,80], sortname: 'id', sortorder: 'desc', viewrecords: true, gridview: true, caption: 'Pending Assignments', ondblClickRow: function(rowid) { $(this).jqGrid('editGridRow', rowid, {width:450,Height:400,recreateForm:true,closeAfterEdit:true, closeOnEscape:true,reloadAfterSubmit:false, modal:true,mtype:'post'});} }); jQuery("#minibutton").click( function(){ var selectedrows = $("#list").jqGrid('getGridParam','selarrrow'); if(selectedrows.length) { for(var i=0;i<selectedrows.length; i++) { var selecteddatais = $("#list").jqGrid('getRowData',selectedrows[i]); var rows=JSON.stringify(selecteddatais) var postArray = {json:rows}; $.ajax({ type: "POST", url: "jsonsend.php", data: postArray, dataType: "json", error: function () { alert("An error occurred."); }, success: function (data) { } }); $( '#list' ).trigger( 'reloadGrid', [{ page: 1}] );//reload grid} }} }); }); 

PHP:

  // connect to the MySQL database server $con = mysql_connect($dbhost, $dbuser, $dbpassword); if (!$con) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($database,$con) or die("Error connecting to db."); //First decode the array $arr = $_POST["json"]; $decarr = json_decode($arr, true); $count = count($decarr); $values = array(); // This will hold our array values so we do one single insert for ($x=0; $x  

只需删除多余的postdefs。

 //First decode the array $arr = $_POST["json"]; $decarr = json_decode($arr, true); $count = count($decarr); for ($x=0; $x < $count; $x++){ $newrec = $decarr; $id = $newrec['id']; $name = $newrec['name']; $id_continent = $newrec['id_continent']; $email = $newrec['email']; $lastvisit = $newrec['lastvisit']; $cdate = $newrec['cdate']; $ddate = $newrec['ddate']; } // Create insert array $values[] = "('".$id."', '".$name."', '".$id_continent."', '".$lastvisit."','".$cdate."','".$ddate."','".$email."' )"; // Insert the records $sql = "INSERT INTO finish (id, name, id_continent, lastvisit,cdate,ddate, email) VALUES ".implode(',', $values); $result = mysql_query($sql, $con) or die(mysql_error()); ?>