PDA

View Full Version : I can't delete from a PagingGrid



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

Fran
15 Jul 2007, 11:50 AM
Well first of all I must to say that error tooks me about 4 days going through.

I know it looks like a newbie error but it isn't. It's turning me crazyyyy!!! xD

moonspice
15 Jul 2007, 3:13 PM
perhaps http://extjs.com/forum/showthread.php?t=6939

Fran
17 Jul 2007, 10:06 AM
Nope! I tried this but isn't ok.

In my PHP Script the received data $_POST['delData'] is correct (I tried an SQL UPDATE statement for see the value), but the $json->decode function doesn't run properly and it returns an array with $jsonDelete[$i]->id containing an empty string.

I want to know the problem but if it persist i'll try it by another way, i.e. sending via POST a string with a list of comma separated id values and in the PHP Script split that.

Thanks,
Fran

Fran
17 Jul 2007, 10:32 AM
"Solved":



function doDel2(btn)
{
if(btn == 'yes')
{
var m = grid.getSelections();
var removedData;

for(var i = 0, len = m.length; i < len; i++){
var ss = m[i].get("Expediente");
if(i==0)
removedData = ss;
else
removedData += "," + ss;
ds.remove(m[i]);
}
ds.load({params:{start:0, limit:myPageSize, delData:removedData}});
}
}


PHP Script:



if(isset($_POST['delData'])) {
$removedData = explode(",", $_POST["delData"]);

for($i=0;$i<count($removedData);$i++) {
$sql = "DELETE FROM planes WHERE Expediente = '".$removedData[$i]."';";
if(!@mysql_query($sql) || $success != 'true') $success = 'false';
}
}



Anyway if somebody have the solution for initial problem, post please. I think is a PHP Json Library bug.

Thanks,
Fran