0

Hi I have a jqgrid setup with a custom action button that sends selected rows to a database. I have everything working except that it posts the data 7 times per each row select where I only want it posted once per selected row. Please any and all help appreciated. JQGrid, How to post JSON string to PHP to Process and send to Database?

$decarr= array(
['id'] =>
518
['name'] =>
'Brochure for amada'
['id_continent'] =>
' Ramon'
['lastvisit'] =>
'5/15/2013'
['cdate'] =>
'5/29/2013'
['ddate'] =>
'5/31/2013'
['email'] =>
'<a href="/media-management/uploads/1368166339.zip">Files</a>'
)

PHP:

//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 < $count; $x++){
$newrec = $decarr; 
$id = $newrec['id']; $id = mysql_real_escape_string($id);
$name = $newrec['name']; $name = mysql_real_escape_string($name);
$id_continent = $newrec['id_continent']; $id_continent = mysql_real_escape_string($id_continent);
$email = $newrec['email']; $email = mysql_real_escape_string($email);
$lastvisit = $newrec['lastvisit']; $lastvisit = mysql_real_escape_string($lastvisit); 
$cdate = $newrec['cdate']; $cdate = mysql_real_escape_string($cdate); 
$ddate = $newrec['ddate']; $ddate = mysql_real_escape_string($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());  


?>
4

1 回答 1

0

固定的!我发现变量在其他行中一遍又一遍地重复。非常爱你们。

//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());  


?>
于 2013-05-15T23:46:29.637 回答