tags:

views:

59

answers:

2

Hi Guys

I want to assign delete for each row using sql query but not specifying the row NAME or ID, e.g.: $sql = "DELETE FROM $table WHERE Description1 = 'Description 10'";

...must be dynamically maybe via row ID to delete correct row at any given time?

Please let me know if you want me to eloborate more about the question above, thanks in advance

A: 

If you want to delete all rows within one table just do the following:

DELETE FROM $table

Be careful! All rows will be deleted.

If you want to set the description for every row to an empty string just do:

UPDATE $table SET (Description1 = '')
faileN
thanks faileN, not really I want to have a delete button for each row but that must not done manually. e.g $sql = "DELETE FROM '$table' WHERE id ='1'";
Mali
A: 

Put checkboxes on each row with the ID of the relevant row as the value, and have these posted as an array when you click on the delete button. Then you can simply implode the array you get in PHP and use it in your delete statement as follows (you probably want to add some sanity checks on the posted data though):

$sql = 'DELETE FROM table WHERE ID IN(' . implode(',', $array) . ')';
wimvds
Hi wimvds, I'm bit confused - I don't want to manually add ID as the ID value auto increment as more content get added...
Mali
Well, your question and comments led me to believe that you wanted to know how to delete multiple lines in one go. If that's not what you're asking, then please elaborate more on what it is exactly that you want (an example could help sometimes). Whether or not the ID column is an autoincrement field is irrelevant when you want to delete rows.
wimvds
Hi all guys thanks a lot for your help, I got the solution and my apologies for being unclear.I added a HTML form with submit button using POST method and on Action value I added the the id column at the end form validate page. Please see below:<form method='post' action='delete_item.php?id=".$row['id']."'><input type='submit' value='delete this article' onclick='confirmation()'/></form>and sql statement to delete a selected row from using PHP REQUEST method:$sql="DELETE FROM Press WHERE id = ('$_REQUEST[id]')";
Mali