Jump to content

[SOLVED] Showing MySQL Table Data - Adding some extra things?


JasonO

Recommended Posts

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.


$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.