View Full Version : Resolved Delete all - Then move to another table

01-25-2012, 07:05 PM
hi guys, i have a delete all button in my inbox, that when clicked a message pops up asking if htey really want to do it, then if true it will do the below function, however im not sure as to how i would move everything from one table (inbox) to another table (deletedinbox), whether it should be done using a foreach or similar function. below is my code so far:

if (isset($_POST['deleteall'])){

mysql_query("DELETE FROM `inbox` WHERE `to`='".dbSafe($fetch->username)."'");
//INSERT INTO `deletedinbox`Would be done here

any help on this would be great.



01-25-2012, 07:25 PM
I wouldn't bother moving them.

Instead you need another table called folders. In this table you have the following setup:

id: folder: userid

In your messages table you then at a column called folderid. Simply change the folder id of the message to match the folder in the folders table. Not only will it be more efficient, it'll save your server resources too. Plus it allows for users to create folders with ease - since they're just a number in the database instead of another entire table to be created and scanned.

01-25-2012, 07:25 PM
Heck no. A loop is a complete waste.
Issue an INSERT INTO SELECT statement instead prior to issuing a delete. Once the delete occurs the data is gone. See this link for INSERT SELECT statement: http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

I like Tango's suggestion too. A simple flag of sorts to determine the status would work just as well and take a lot less work to hold onto.

01-25-2012, 11:28 PM
i used your method tango :) it worked a charm :) ill show you my code:

if (isset($_POST['deleteall'])){
mysql_query("UPDATE `inbox` SET `folder`='deleted' WHERE `to`='".dbSafe($fetch->username)."'");