Jump to content

Delete row in mysql


wiggst3r

Recommended Posts

Hi

 

I have a for loop that outputs info from my database.

 

I want next to each to have a link with a delete button, when clicked, the row gets deleted, based on the 'catid'

 

My code is as follows:

 

	foreach($list as $item)
{
	if(isset($_GET['state']) && $_GET['state'] == 'edit' && $_GET['id'] == $item['catid'])
	{
		///display row with values inside form fields

	}
	else
	{
		//display normal row
		?>
		<div id="item_<?=$item['catid'];?>">
		<p class="briefed"><?=$item['briefed'];?></p>
		<p class="job_number"><?=$item['job'];?></p>
		<p class="category"><?=$item['category'];?></p>
		<p class="needed"><?=$item['needed'];?></p>
		<p class="status"><?=$item['status'];?></p>
		<p class="order_id"><?=$item['orderid'];?></p>
		<p class="link"><a href="index.php?state=edit&catid=<?=$item['catid']?>">Edit</a></p>
		<p class="delete"><a href="delete_row.php"></a><img src="images/cross.png" border="0" /></a></p>

		</div>
		<?
	}
}
?>

 

Anyone know what I need to add tot the delete section and what needs to be in delet_row.php?

 

Thanks

Link to comment
Share on other sites

You need some id that can be used to reference the row you want to delete:

<p class="delete"><a href="delete_row.php?p=<?php item['primarykey'] ?>"></a><img src="images/cross.png" border="0" /></a></p>

 

Then, in delete_row.php:

"DELETE FROM Table WHERE PrimaryKey = ".$_GET['primarykey'];

Link to comment
Share on other sites

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.