PHP Classes

Delete

Recommend this page to a friend!

      Eyesis Data Grid Control  >  All threads  >  Delete  >  (Un) Subscribe thread alerts  
Subject:Delete
Summary:Implementing the Delete function using example 3
Messages:5
Author:Douglas
Date:2009-01-16 20:02:19
Update:2011-12-04 18:43:25
 

 


  1. Delete   Reply   Report abuse  
Picture of Douglas Douglas - 2009-01-16 20:02:19
Does anyone have an example of implementing actual Delete funtion?

$x->addStandardControl(EyeDataGrid::STDCTRL_DELETE, "alert('Deleting %ID%')");

Currently this just displays an alert popup.

How do you implement it so it actually performs the delete.

  2. Re: Delete   Reply   Report abuse  
Picture of Sören Monvall Sören Monvall - 2009-01-20 14:25:21 - In reply to message 1 from Douglas
Sorry but so far I cannot help you because when I try to test the application I get stopped already on line 28 and if I commentout that line I get parse error on next statement. Perhaps you can give me a hint about what I am doing wrong. The file I mean is class.eyemysqladap.ink.php. I have the latest Apach, Mysql,php from XAMPP. All files are in folder htdocs.
This is the error:
"Parse error: parse error in C:\xampp\htdocs\class.eyemysqladap.inc.php on line 28" and line 28 is this: private $link;

  3. Re: Delete   Reply   Report abuse  
Picture of Razmin Martinez Razmin Martinez - 2010-12-23 17:28:44 - In reply to message 1 from Douglas
please help, i am in the same situation.

  4. Re: Delete   Reply   Report abuse  
Picture of Ng Yi Ying Ng Yi Ying - 2011-08-01 16:07:11 - In reply to message 3 from Razmin Martinez
I might be to late for this. But just for sharing purpose:
The solution may look something like this:

$x->addStandardControl(EyeDataGrid::STDCTRL_DELETE, "window.location.replace('yourdeletephpcode.php?&primaryKeyFieldName=%_P%')");

The javascript is written to navigate the page to your delete php script, by passing the value through the variable over the URL (i.e. primaryKeyFieldName). You may write your delete function there (i.e. yourdeletephpcode.php).

You may get the value of the primary key by requesting $_GET["primaryKeyFieldName"] over your delete php script.

Cheers!

  5. Re: Delete   Reply   Report abuse  
Picture of nugraha_isnan nugraha_isnan - 2011-12-04 18:43:25 - In reply to message 1 from Douglas
create function with parameter... better do with ajax..


ElementID= the html element ID that would take ajax effect
ID= your primary key or the fieldname of your delete condition
handlePage= PHP code that would do the delete code

function deldata(handlePage,ElementID,ID) {
if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
var obj = document.getElementById(ElementID);
var form = obj.innerHTML;
obj.innerHTML = 'Deleting Data, please wait..';
xmlhttp.open('POST', handlePage, true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText + '<br>' + form;
setTimeout(tblReset(), 1000);
} else {
alert('Error : ' + xmlhttp.statusText);
}
}
}
var param = 'ID=' + ID;
xmlhttp.send(param);
}
}


and this is how to call your ajax function

$x->addStandardControl(EyeDataGrid::STDCTRL_DELETE,
"deldata('yourhandlePage.php','yourElementID','%yourprimarykey%')");

to make it easier i'll give you the handlepage example
<?php

$id = $_POST['ID'];
$query = "delete from table where yourID='" . $id . "'";
$result= mysql_query($query);
if ($result)
{
echo 'data has been deleted';
} else
{
echo '<font color="red">Error, CAN NOT DELETE DATA</font>';
}

?>


ajax is easy... cheersssss.........