Delete question-how to delete a php product category?

Source: Internet
Author: User
{Code ...}
Your location: item category column Category ID category tree Category name parent category ID parent category path item category management 6 appliances 0 0, modify | copy | delete 15 black/white TV sets 6, modify | copy | delete 27 washing machine 6, modify | copy | delete 28 LCD TV 6, modify | copy | delete 3 Women's 0, modify | copy | delete 12 casual pants 3, modify | copy | delete 7 mobile phones 0 0, modify | copy | delete 8 iphone 7, modify | copy | delete 10 iphone6s 8, 8. modify | copy | delete 9 Huawei 7, modify | copy | delete 11 Huawei mate9 9, modify | copy | delete 19 vivo 7, modify | copy | delete 26 vivoX7 19 0, 7, 19, modify | copy | delete // How to make items in the table above Category deletion? Delete parent category = parent + child $ id =_ _ GET ['id']; $ SQL = "select path from type WHERE path like '% $ id %'"; $ rs = mysql_query ($ SQL); $ arr = mysql_fetch_assoc ($ rs ); if ($ arr) {$ path = "and path like '% $ id %'";} else {$ path = '';} $ where = "where id = {$ id} {$ path}"; $ sql2 = "delete from type $ where"; // echo $ sql2; die (); $ rs = mysql_query ($ sql2); if (mysql_affected_rows ()> 0) {echo 'deletion successfully';} else {echo 'deletion failed';} break; // why can't I delete products with subcategories in my code? Can the parent class be executed only after the sub-category is deleted? // is the sequence problem of where and? For example, if you want to delete a women's dress, you need to delete the casual trousers first. but what should I do if I want to delete them directly ??

Reply content:
Your location: item category column Category ID category tree Category name parent category ID parent category path item category management 6 appliances 0 0, modify | copy | delete 15 black/white TV sets 6, modify | copy | delete 27 washing machine 6, modify | copy | delete 28 LCD TV 6, modify | copy | delete 3 Women's 0, modify | copy | delete 12 casual pants 3, modify | copy | delete 7 mobile phones 0 0, modify | copy | delete 8 iphone 7, modify | copy | delete 10 iphone6s 8, 8. modify | copy | delete 9 Huawei 7, modify | copy | delete 11 Huawei mate9 9, modify | copy | delete 19 vivo 7, modify | copy | delete 26 vivoX7 19 0, 7, 19, modify | copy | delete // How to make items in the table above Category deletion? Delete parent category = parent + child $ id =_ _ GET ['id']; $ SQL = "select path from type WHERE path like '% $ id %'"; $ rs = mysql_query ($ SQL); $ arr = mysql_fetch_assoc ($ rs ); if ($ arr) {$ path = "and path like '% $ id %'";} else {$ path = '';} $ where = "where id = {$ id} {$ path}"; $ sql2 = "delete from type $ where"; // echo $ sql2; die (); $ rs = mysql_query ($ sql2); if (mysql_affected_rows ()> 0) {echo 'deletion successfully';} else {echo 'deletion failed';} break; // why can't I delete products with subcategories in my code? Can the parent class be executed only after the sub-category is deleted? // is the sequence problem of where and? For example, if you want to delete a women's dress, you need to delete the casual trousers first. but what should I do if I want to delete them directly ??

Delete from table where id = 7 or path like '%, 7, %'

Based on my experience, I have the following suggestions:
1. when you delete a product category, you must check the database to verify that the category contains a subcategory. If yes, you cannot delete the category.
2. before deleting a category, you must delete all the sub-categories under the category.
3. if you do not follow these steps, junk data will be generated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.