Jump to content

Recommended Posts

Hi,

 

I'm having trouble figuring out how to do the following.

 

I make a mysql request to give me all of the entries in a table.

 

For each result I add a new html table row to my form with the results data and a "delete" of type submit.

 

I want to know if it possible to assign the primary key value of each result entry to each delete button so that when the delete button is hit the primary key of the entry is sent to a script to remove that entry from the database table.

 

So if I had 3 results whose primary keys where 1, 2 and3  and I clicked on delete button 2 I would send "2" to my delete script.

 

I'm not sure if I'm going about this the right way?

I'm kinda in the early stage of learning PHP so any help or advice would very well recieved.

Thanks!  :)

 

while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {

echo "	<tr>
		<td align=\"left\">{$row[0]}</td> //$row[0] contains the primary key
		<td align=\"left\">{$row[2]}</td>
		<td align=\"left\"><input type=\"submit\" name=\"delete\" value=\"$row[0]\"></td>
	</tr>\n";

}

if (isset($_POST['delete'])) {
// my delete function with the correct primary key to use
}

instead of a delete button you could do a link with the id and an image.

echo "<td align='left'>".$row[0]."</td>
<td align='left'>".$row[2]."</td>
<td align='left'><a href='?action=delete&id=".$row[0]."'><img src='your_delete_icon.gif' border='0'></a></td>

 

 

then at the beginning of your page check for it

if(isset($_GET['action']) && $_GET['action']=="delete")
{
                 // your delete function here would use $_GET['id'] 
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.