Sysadmin20 Posted February 3, 2023 Share Posted February 3, 2023 (edited) Hello friends, My name is Jay and I'm a sys admin and have very little experience with PHP and stuff. We have an internal system developed by a dev and I'm trying to make some changes to it and hoping if someone could help. So we have a simple results page which will fetch records from a MySQL table and display in table format. This is the code file - https://pastebin.com/VwxAVY9y I'm trying to add a delete button next to each records and delete those records dynamically. I don't need a warning or any prompt/confirmation etc. So I added a 3rd column as "<th>Action</th>" but I'm having a hard time incorporating the AJAX delete function within the echo "<td> </td>" section. I did quite a lot of google search and couldn't figure this out. What I want is a colum with a delete button like this attached screenshot. Any help is appreciated Cheers Jay Edited February 3, 2023 by Sysadmin20 Quote Link to comment https://forums.phpfreaks.com/topic/315874-help-with-php-form-and-action-button/ Share on other sites More sharing options...
requinix Posted February 3, 2023 Share Posted February 3, 2023 Each button needs to know which result it's supposed to delete. Since you're doing this with AJAX you have a lot of flexibility in how to go about it, but my preferred is a data attribute. <button data-deletes-record="(id goes here)">Delete</button> With jQuery, you can then wait for a click event on a button with that attribute, $("#allRecords").on("click", "button[data-deletes-record]", function() { Inside that you can grab the ID with .attr() or .data() and then pass it through AJAX... Quote Link to comment https://forums.phpfreaks.com/topic/315874-help-with-php-form-and-action-button/#findComment-1605340 Share on other sites More sharing options...
Sysadmin20 Posted February 3, 2023 Author Share Posted February 3, 2023 6 minutes ago, requinix said: Each button needs to know which result it's supposed to delete. Since you're doing this with AJAX you have a lot of flexibility in how to go about it, but my preferred is a data attribute. <button data-deletes-record="(id goes here)">Delete</button> With jQuery, you can then wait for a click event on a button with that attribute, $("#allRecords").on("click", "button[data-deletes-record]", function() { Inside that you can grab the ID with .attr() or .data() and then pass it through AJAX... Thanks for the reply. I'm not sure if I can write that code but at least now I know what to research online. I'll give it a try. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/315874-help-with-php-form-and-action-button/#findComment-1605341 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.