Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts

    Delete all - Then move to another table

    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:

    PHP Code:
    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.

    Cheers.

    Dan
    Last edited by Dan13071992; 01-25-2012 at 11:31 PM.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,311
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    Dan13071992 (01-25-2012)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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/...rt-select.html

    Edit:
    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.

  • Users who have thanked Fou-Lu for this post:

    Dan13071992 (01-25-2012)

  • #4
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    i used your method tango it worked a charm ill show you my code:

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


    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •