wiggst3r Posted July 8, 2008 Share Posted July 8, 2008 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 Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 8, 2008 Share Posted July 8, 2008 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']; Quote Link to comment Share on other sites More sharing options...
wiggst3r Posted July 8, 2008 Author Share Posted July 8, 2008 I used this: <p class="delete"><a href="delete_row.php?catid=<?=$item['catid']?>">delete</a></p> Worked perfectly Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.