PDA

View Full Version : Deleting table data based on page interaction


ceylon
05-11-2009, 11:52 PM
I may be over complicating this, but basically I need to emulate the delete row functionality in phpmyadmin on a table im writing dynamically. When clicked on the row I'd like to have it prompt with a are you sure you want to delete y/n and then submit the page, the code would automatically rewrite the table with the newly deleted table row. Where I'm stuck at is starting with how to mesh the js with the php to interact with the table.
Below is a partial piece of the table im generating. Basically when TR with ID example is clicked id need to initiate the deletion (each of the 4 td's are pulled over from the table):
<td>Department</td>
<td>Phone</td>
<td>Extension</td>
<td>Email Address or Notes</td>
</tr>

<tr id="example">
<td>Bananas</td>
<td>541-997-4988</td>
<td>4988</td>
<td>Bananas</td>
</tr>

Fumigator
05-12-2009, 12:38 AM
The delete icon on each row must contain a reference to the ID of the row in the table you want to delete. You can either use a link to a PHP script along with a query string (i.e. <a href="delete.php?id=12345">Delete</a>), or you can label an icon or button with an ID value of the row's ID (i.e. <input type="button" id="12345" value="Delete">).

Let's focus on the first option, using a link. The link will work as it is: in your delete.php script you need to capture the id in the query string using $_GET['id'], and then use it in a MySQL query to delete the proper row.

You just need to intercept the link to confirm the deletion. To do this, you want to use Javascript.

ceylon
05-12-2009, 09:12 PM
thanks bud, makes perfect sense and easy to implement :) I had the jist of it, but was def overcomplicating! thanks again :cool: