Fran
15 Jul 2007, 7:44 AM
I have a problem deleting rows from database with a PagingGrid component. I'm using MySQL and PHP for server side. Here's the code:
Delete function:
function doDel2(btn)
{
if(btn == 'yes')
{
var m = grid.getSelections();
var jsonData = "[";
for(var i = 0, len = m.length; i < len; i++){
var ss = "{\"id\":\"" + m[i].get("Expediente") + "\"}";
if(i==0)
jsonData = jsonData + ss ;
else
jsonData = jsonData + "," + ss;
ds.remove(m[i]);
}
jsonData = jsonData + "]";
alert(jsonData);
ds.load({params:{start:0, limit:myPageSize, delData:jsonData}});
}
}
The function alert() shows me that is all correct.
...and this is my server-side delete script:
<?php
include_once "JSON.php";
include_once "conexion.php";
$json = new Services_JSON();
$success = 'true';
$jsonDelete = $json->decode($_POST['delData']);
for($i=0;$i<count($jsonDelete);$i++) {
$sql = "DELETE FROM planes WHERE Expediente = '".$jsonDelete[$i]->id."';";
if(!mysql_query($sql) || $success != 'true') $success = 'false';
}
print('[{"success":'.$success.'}]');
?>One of the things i can observe is $jsonDelete[$i]->id doesn't returns me anything, but if I try to execute directly delete.php (this php-script) changing $_POST['delData'] for resulting data from the javascript alert (i.e.: [{"id":"exp2"}]), this goes ok.
I think don't forget anything, if so, please ask me ;)
Thanks,
Fran
Delete function:
function doDel2(btn)
{
if(btn == 'yes')
{
var m = grid.getSelections();
var jsonData = "[";
for(var i = 0, len = m.length; i < len; i++){
var ss = "{\"id\":\"" + m[i].get("Expediente") + "\"}";
if(i==0)
jsonData = jsonData + ss ;
else
jsonData = jsonData + "," + ss;
ds.remove(m[i]);
}
jsonData = jsonData + "]";
alert(jsonData);
ds.load({params:{start:0, limit:myPageSize, delData:jsonData}});
}
}
The function alert() shows me that is all correct.
...and this is my server-side delete script:
<?php
include_once "JSON.php";
include_once "conexion.php";
$json = new Services_JSON();
$success = 'true';
$jsonDelete = $json->decode($_POST['delData']);
for($i=0;$i<count($jsonDelete);$i++) {
$sql = "DELETE FROM planes WHERE Expediente = '".$jsonDelete[$i]->id."';";
if(!mysql_query($sql) || $success != 'true') $success = 'false';
}
print('[{"success":'.$success.'}]');
?>One of the things i can observe is $jsonDelete[$i]->id doesn't returns me anything, but if I try to execute directly delete.php (this php-script) changing $_POST['delData'] for resulting data from the javascript alert (i.e.: [{"id":"exp2"}]), this goes ok.
I think don't forget anything, if so, please ask me ;)
Thanks,
Fran