Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    Senior Member ericbusch's Avatar
    Join Date
    Aug 2003
    Location
    Daejeon, South Korea
    Posts
    241
    Member #
    2779
    I want to make an interface for myself where I can delete multiple files(rows) from MySQL database table. I want each row to be listed back to me along with a checkbox so I can check the specific rows i want to delete and do it all in one shot.

    First: Is this possible using PHP and MySQL?

    Second: Any suggestions on how to do this. I was thinking of putting the
    PHP Code:
    DELETE FROM table WHERE 
    within a while loop. That way, each file will be displayed back to me and I can click the ones I don't want.

    Thanks, Eric
    Blogs For Sale - Each blog is packed with 1000s of signatures and ads are highly integrated into the site. Great CTR! Completely customizable from Admin CP. On Sale!
    Complete Websites For Sale - Fantastic looking sites rich with content. Come complete with domain names. I only have a couple of these.

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    For your HTML:
    Code:
    <input type="checkbox" name="deleted_items" value="1" />
    <input type="checkbox" name="deleted_items" value="2" />
    <input type="checkbox" name="deleted_items" value="3" />
    <input type="checkbox" name="deleted_items" value="4" />
    <input type="checkbox" name="deleted_items" value="5" />
    For your SQL string
    PHP Code:
    $sql "DELETE FROM table WHERE column IN (".$_POST["deleted_items"].")"
    Essentially, you're concatenating the posted value for deleted items into the IN (value1, value2) SQL syntax. Since the default value of the array is a comma delimited string, it will insert perfectly (if it's an INT column.... don't use this for VARCHARs !!!!)

  4. #3
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Transio, is it possible (are there any syntax) to delete a specified (multiple) number of rows with a query like:

    DELETE FROM tableName WHERE columname='columnvalue, columnvalue, columnvalue'

    Obviously the above wouldn't work, but I guess you understand what I mean.
    S. Rosland

  5. #4
    Senior Member ericbusch's Avatar
    Join Date
    Aug 2003
    Location
    Daejeon, South Korea
    Posts
    241
    Member #
    2779
    I was wondering the same thing. I could be wrong, but it seems the first example used hard-coded HTML. I am curious if there are any answers to Rosland's more specific quesion...

    Eric
    Blogs For Sale - Each blog is packed with 1000s of signatures and ads are highly integrated into the site. Great CTR! Completely customizable from Admin CP. On Sale!
    Complete Websites For Sale - Fantastic looking sites rich with content. Come complete with domain names. I only have a couple of these.

  6. #5
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    The SQL is in my sample above, only concatenated with PHP... the correct syntax is:
    Code:
    -- INT column
    DELETE FROM table WHERE column IN (1, 2, 3);
    
    -- VARCHAR column
    DELETE FROM table WHERE column IN ('A', 'B', 'C');
    The reason you only want to use my sample above with the INT example here (see my note in my previous post) is because of the way checkboxes return their values in a form.

    What I mean is that given this example:
    Code:
    <input type="checkbox" name="deleted_items" value="1" />
    <input type="checkbox" name="deleted_items" value="2" />
    <input type="checkbox" name="deleted_items" value="3" />
    <input type="checkbox" name="deleted_items" value="4" />
    <input type="checkbox" name="deleted_items" value="5" />
    If you check all the boxes and submit the form, the $_POST value for "deleted_items" will return the value 1, 2, 3, 4, 5 (as a string). By concatenating that string in the sample above with the "DELETE FROM table WHERE column IN (" and the "deleted_items" string and ");" you wind up with this derivation:
    PHP Code:
    $sql "DELETE FROM table WHERE column IN (".$_POST["deleted_items"].")";
    $sql "DELETE FROM table WHERE column IN ("."1, 2, 3, 4, 5".")";
    $sql "DELETE FROM table WHERE column IN (1, 2, 3, 4, 5)"
    I hope you see now how the concept works for using integer id's in deleting multiple columns.

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    By the way, you can replace this code:
    Code:
    <input type="checkbox" name="deleted_items" value="1" />
    <input type="checkbox" name="deleted_items" value="2" />
    <input type="checkbox" name="deleted_items" value="3" />
    <input type="checkbox" name="deleted_items" value="4" />
    <input type="checkbox" name="deleted_items" value="5" />
    With a list generated from a PHP query of your table.

  8. #7
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    I'm turning this into a tutorial... I at least deserve some turtle dollars outta my efforts !!

  9. #8
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    I made the tutorial... it is here: http://www.webdesignforums.net/showt...threadid=10043

  10. #9
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Excellent tutorial!
    S. Rosland

  11. #10
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Check it again... I just updated it.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:32 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com