I was wondering if anyone has any insight on how to delete rows from a database. Here is what I actually want:
A list of names is displayed from a table in the database. Next to each name there is a Delete button. When the user presses delete the specific user is deleted from the database and the form refreshes with the users minus the deleted one.
I know that this should happen with PHP but I am still working on finding out how to do it.
Any input will be helpful.
Pericles
A list of names is displayed from a table in the database. Next to each name there is a Delete button. When the user presses delete the specific user is deleted from the database and the form refreshes with the users minus the deleted one.
I know that this should happen with PHP but I am still working on finding out how to do it.
Any input will be helpful.
Pericles
Hi Pericles,
This is easy to do in ChronoConnectivity with CFv3 (part of the built-in code) and probably fairly easy with the Db Multi Record loader in CFv4.
Bob
This is easy to do in ChronoConnectivity with CFv3 (part of the built-in code) and probably fairly easy with the Db Multi Record loader in CFv4.
Bob
I found this code http://davidwalsh.name/animated-ajax-record-deletion-mootools that shows you how to delete rows and have a nice slideout effect. I am not really interested in the effect but it does not hurt.
I adapted the code as follows:
Load JS Code at the start:
Custom Code after the Multi Record Loader:
The records are loaded correctly and the data is displayed. When I click on the delete the row turns red but then nothing else happens.
Can you spot any mistakes in the code that could make this work?
I am not sure where isset code should be placed or if I need to have an on ajax event like the dropdown example.
Thanks,
Pericles
I adapted the code as follows:
Load JS Code at the start:
window.addEvent('domready',function() {
$$('a.delete').each(function(el) {
el.addEvent('click',function(e) {
e.stop();
var parent = el.getParent('div');
var request = new Request({
url: 'mootools-record-delete.php',
link: 'chain',
method: 'get',
data: {'delete': parent.get('id').replace('record-',''),ajax: 1},
onRequest: function() {
new Fx.Tween(parent,{duration:300}).start('background-color', '#fb6c6c');
},
onSuccess: function() {
new Fx.Slide(parent,{duration:300,onComplete: function() {
parent.dispose();
}
}).slideOut();
}
}).send();
});
});
});
Custom Code after the Multi Record Loader:
<?php
if(isset($_GET['delete']))
{
$query = 'DELETE FROM `#__chronoforms_data_frmTeam2League` WHERE cf_id = '.(int)$_GET['delete'];
$result = mysql_query($query,$link);
}
foreach($form->data['Team2League'] as $detail)
{
echo '<div class="record" id="record-'.$detail['cf_id'].'">
<a href="?delete='.$detail['cf_id'].'" class="delete">Delete </a><strong>'.$detail['team'].'</strong>
</div>';
}
?>
The records are loaded correctly and the data is displayed. When I click on the delete the row turns red but then nothing else happens.
Can you spot any mistakes in the code that could make this work?
I am not sure where isset code should be placed or if I need to have an on ajax event like the dropdown example.
Thanks,
Pericles
I found one error where I had the wrong URL in the request. I changed this to:
This now deletes the row and animates it but when I refresh the page the data is not deleted from the table.
Pericles
url: 'index.php?option=com_chronoforms&chronoform=frmTeam2LeagueReport&event=ajax&format=raw',
This now deletes the row and animates it but when I refresh the page the data is not deleted from the table.
Pericles
This topic is locked and no more replies can be posted.