I’ve been using PHP to correlate my HTML table’s row ID’s with my MySQL id’s so that when I delete a table row it also deletes the record in the database. However, I just managed to get the AJAX data entry working so there’s no page refresh when someone adds another row to the table (and the database).
I still have a delete option for the newly added row and I’d like to be able to delete the newly-added record, only there’s no ID assignment for the newly created row (because it wasn’t generated by PHP). So the only thing happens is the row disappears from the HTML table, but upon refresh reappeaers because it’s not actually getting deleted from the database. I’m having trouble thinking of a way to be able to figure out what database ID the item has when the page hasn’t been refreshed (or if there’s a better way to do this altogether).
Can anyone suggest to me some ways to go about doing this?
Your table id should not be used to correlate to MySQL ID. They don’t really work that way. Your HTML table should have a hidden field stores primary key for each row and use that to correlate to your database. When adding record, the Ajax should return the result with the primary key to newly added record. When delete, send this key together with the delete command back to another page through Ajax. Similarly, you can also do update this way.