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
https://forums.phpfreaks.com/topic/113739-delete-row-in-mysql/
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
https://forums.phpfreaks.com/topic/113739-delete-row-in-mysql/#findComment-584528
Share on other sites

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.