Hi all. I'm new to php and am trying to get past something that's probably quite simple. I've got a form with a while loop showing a list of tasks. The task can be deleted with this button:
mysql_select_db($database_test, $test);
$query_tasks = "SELECT * FROM tasks";
$Recordset2 = mysql_query($query_tasks, $test) or die(mysql_error());
$row_tasks = mysql_fetch_assoc($tasks);
$totalRows_tasks = mysql_num_rows($tasks);
I need to edit this code so the record being passed inserts into another table before it gets deleted. Can anyone point me in the right direction? Thanks guys
My first suggestion would be to not move it, but instead mark it as deleted. This could either be a "status" field which can have different values to indicate what status applies, including, for example, 'D' for deleted. Or you could just have a separate column only for indicating when it is deleted. This would mean you would update your regular listing queries to include a check of that column's value, e.g.:
Code:
. . . WHERE status != 'D' . . .
Why I like such an approach is that it makes it easy to generate reports and such since all the historical data is in that one table, plus I just don't like having more tables than I really need.
If you do want/need to go ahead with the idea of moving it to another table, probably the simplest approach is:
Code:
INSERT INTO new_table (col1, col2, col3)
SELECT col1, col2, col3 FROM old_table WHERE col1='foo'; -- assuming for this example `col1` is the primary key
Obviously you want to do that before you then delete that record from `old_table`.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks