JasonO Posted February 22, 2007 Share Posted February 22, 2007 Hi I have managed to display the data from a table that shows the fields in each row until theres no more rows. I need to be able to make it so a button appears next to each record allowing you to delete it. Does anyone have any idea how I could do this? I can't make a link to a script that lets me remove it, it wouldn't know what the id is for the record unless I tell it somehow. Here is my current script I have to show the data. Everything works, and im assuming what I need to add is placed somewhere in the code below $query = "SELECT * FROM newcustomers"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<tr> <td>{$row['id']} </td> <td>{$row['name']} </td> <td>{$row['email']} </td> <td>{$row['server']} </td> <td>{$row['slots']} </td> <td>{$row['password']}</td> <td>{$row['ip']} </td> </tr>"; } Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/39685-solved-showing-mysql-table-data-adding-some-extra-things/ Share on other sites More sharing options...
jcbarr Posted February 22, 2007 Share Posted February 22, 2007 $delete=$_GET['id']; if (!empty($delete)) { mysql_query("DELETE FROM newcustomers WHERE id='$delete'"); } $query = "SELECT * FROM newcustomers"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<tr> <td>{$row['id']} </td> <td>{$row['name']} </td> <td>{$row['email']} </td> <td>{$row['server']} </td> <td>{$row['slots']} </td> <td>{$row['password']}</td> <td>{$row['ip']} </td> <td><a href=$PHP_SELF?id={$row['id]}>DELETE</a></td> </tr>"; } That will only delete one record at a time when the user clicks the link to delete but it should work. You could also make them radio buttons and dump them in to an array and delete each entry with a foreach loop as well, but that is a little more work. Link to comment https://forums.phpfreaks.com/topic/39685-solved-showing-mysql-table-data-adding-some-extra-things/#findComment-191580 Share on other sites More sharing options...
JasonO Posted February 22, 2007 Author Share Posted February 22, 2007 Excellent. Exactly what I wanted. Thanks a lot for your help. Edit : Had to edit a line. You missed a ' from where the delete link is. <td><a href=$PHP_SELF?id={$row['id']}>DELETE</a></td> Not a problem though, I fixed it. Link to comment https://forums.phpfreaks.com/topic/39685-solved-showing-mysql-table-data-adding-some-extra-things/#findComment-191583 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.