0
<?php
$query = "SELECT * FROM table1";
$result = mysql_query($query)
or die ("Query Failed: " . mysql_error());
    echo "<TABLE BORDER = '1'>";
    echo "<TR>";
    echo "<TH>Unique ID</TH><TH>URL</TH><TH>First Name</TH><TH>Last Name</TH><TH>Mail</TH><TH>Time Entered</TH>";
    echo "</TR>";    
while ($row = mysql_fetch_array($result))
     {
echo "<TR>";
echo "<TD>",
$row['Unique_ID'], "</TD><TD>",
$row['url'], "</TD><TD>",
$row['fname'], "</TD><TD>",
$row['lname'], "</TD><TD>",
$row['mail'], "</TD><TD>",
$row['time'], "</TD>";
echo "</TR>";  
     }
    echo "</TABLE>";
    echo "<br>";
?>

I have the above piece of code, and I would like to automatically insert buttons at the end of each row: edit & delete. Please help?

Also, in the same piece of code-these buttons-I would like to create them as simple MySQL quereid, but then ho will the script know for which row to apply the queries?

1
  • You can do ajax and put a button for each row or you could just do a simple form for them. Basically you could pass all the values to the new form (this would require more HTML) or you can pass the unique ID and do another query to get the values and set them in the form to edit it. Then you would save the form just like normal. Pretty similar method for delete, except you could have a confirmation page, javascript to verify, or just delete it. Commented Dec 12, 2010 at 21:27

1 Answer 1

2
echo '<td><form action="/delete.php" method="POST">';
echo '<input type="hidden" name="id" value="'.$row['Unique_ID'].'">';
echo '<input type="submit" value="Delete"></form>';
echo '<form action="/edit.php" method="GET">';
echo '<input type="hidden" name="id" value="'.$row['Unique_ID'].'">';
echo '<input type="submit" value="Edit"></form></td>';

Something like that?

EDIT: cleaned up a bit for clarity

Sign up to request clarification or add additional context in comments.

6 Comments

Something like that, especially in the form which can be read by a human. And use POST method for delete.
is the .$row variable looking at which row the button is in and by that choosing thw Unique ID? If so-great. But this won't put buttons in all the rows...that's the solution I need
@WideBlade this would. If you put it into each row
@FoxBunny-Yes, Exactly. I've been looking for something like this for 3 weeks.
I noticed a problem though-the hidden values do not contain anything.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.