EllisLab text mark
Advanced Search
     
Flexigrid - delete.php is not working - help needed!!!
Posted: 04 February 2010 07:19 PM
Joined: 2010-01-24
12 posts

I have been trying to get delete.php to work from http://sanderkorvemaker.nl/test/flexigrid/ again , but somehow it is not deleting from my table, even when i have enabled the sql runSQL to do the delete action.

I read someone has the same problem at this post. http://ellislab.com/forums/viewthread/75326/P270/
post#280, that all they did is remove the trailing comma (,) but where is the trailing comma (,)?

<? 
error_reporting
(0);
function 
runSQL($rsql{
    $hostname 
"localhost";
    
$username "root";
    
$password "";
    
$dbname   "tutorial";
    
$connect mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
    
$db mysql_select_db($dbname);
    
$result mysql_query($rsql) or die ('test'); 
    return 
$result;
    
mysql_close($connect);
}

$items 
rtrim($_POST['items'],",");
$sql "DELETE FROM 'service_table' WHERE 'id' IN ($items)";

$total count(explode(",",$items)); 
$result runSQL($sql);
$total mysql_affected_rows();
/// Line 18/19 commented for demo purposes. The MySQL query is not executed in this case. When line 18 and 19 are uncommented, the MySQL query will be executed. 
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " gmdate"D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json "";
$json .= "{\n";
$json .= "query: '".$sql."',\n";
$json .= "total: $total,\n";
$json .= "}\n";
echo 
$json;
 
?> 
 
Posted: 04 February 2010 08:25 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2008-07-16
664 posts
$json .= "total: $total,\n"

..there. After $total

 
Posted: 04 February 2010 10:36 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-01-24
12 posts

thank you so much, it works.

but I also notice another thing.

$sql "DELETE FROM `service_table` WHERE `id` IN ($items)"

// WORKS

if I change to ` to ‘:

$sql "DELETE FROM 'service_table' WHERE 'id' IN ($items)"

// DO NOT WORK

Now I wish to make a update.php, from this delete.php

$sql "UPDATE service_table SET granted=`1` WHERE `id` IN ($items)"

but it just does not work, is it because of the json? Or is there anything wrong with my UPDATE statement?

In my update php, I want to update “granted” to true.

 
Posted: 05 February 2010 03:05 AM   [ # 3 ]   [ Rating: 0 ]
Joined: 2010-01-24
12 posts

ok, my update.php works now.
But the json is not working for the update.php. I am not familiar with json, can anyone help me on the json below? It is the same example from delete.php, I only change the $sql for updating the database.

$items rtrim($_POST['items'],",");
$sql "UPDATE service_table SET granted='1' WHERE id IN ($items)";

$total count(explode(",",$items)); 
$result runSQL($sql);
$total mysql_affected_rows(); 


header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " gmdate"D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");

$json "";
$json .= "{\n";
$json .= "query: '".$sql."',\n";
$json .= "total: $total\n";
$json .= "}\n";
echo 
$json;
 
?> 


I do not receive the json success alert box such as this.
query: ‘UPDATE service_table SET granted=‘1’ WHERE id IN 1’,
total: 3,

So that is why I am guessing it is the json. is it?

 
Posted: 05 February 2010 07:20 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2010-01-24
12 posts

first method, I try adding the error in ajax, and it prints out ParserError

error: function(XMLHttpRequesttextStatuserrorThrown)
{
     alert(textStatus 
" | " errorThrown);     // throw ParserError

 

my second method, I use json_encode but it throw $sql and $total as undefined.

$json "";
$json .= "{\n";
$json .= "query: '".$sql."',\n";
$json .= "total: $total\n";
$json .= "}\n";
echo 
json_encode($json); 

anyone has any idea of this?

 
Posted: 10 February 2010 09:09 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-07-16
664 posts

Do you use Firebug? If not, please do smile With that you can see what kind of response you get from the server and see that the response is valid.

 
Posted: 11 February 2010 03:16 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2010-01-24
12 posts

Oh, it needs FireFox and Firebug. Thanks, I will check it out.

 
Posted: 12 February 2010 09:37 AM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-03
183 posts

I suggest jqgrid.You can see its power here and the codeigniter implementation here.

 Signature 

“Do Something To Reduce Your Energy Use,The World Is Running Out Of Known Sources Of Energy”

 
Posted: 12 February 2010 11:45 AM   [ # 8 ]   [ Rating: 0 ]
Joined: 2010-01-24
12 posts

jqgrid looks really impressive, too bad it is quite expensive.

 
Posted: 12 February 2010 11:54 AM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-03
183 posts

That’s what i thought the first time but i soon learn’t that you could actually use it and buy the license when you need it,its actually based on jquery which is free.

 Signature 

“Do Something To Reduce Your Energy Use,The World Is Running Out Of Known Sources Of Energy”