The idea of correcting the writing method of database classification table

is about the operation of adding and modifying multi-classification in the background of content management.

clipboard.png

thinkphp


clipboard.png

because the database operation of the thinkphp array does not know how to do so, the stupidest method is to delete all the specified classification records that already exist in the data table, regardless of whether you add or modify them, and then split the categories array into the table one by one.

I have no experience and I don"t know if there is a problem with this.

Php
Jan.23,2022

No problem, the structure in the above figure looks like an intermediate table, which is only used to associate the relationship between articles and categories. Another method of model association is provided below
.
first of all, I don't know which version of ThinkPHP you are using, let's just think that ThinkPHP 5.0.
see your data table, then your association should be id of the post (assuming article table) table category (assuming classification table) id . The structure of your intermediate table is shown in the figure above.
so one of the model operations in Tp 5.0is model association. An article can correspond to multiple classifications, which is an one-to-many model relationship. Then there are article tables, classification tables, and intermediate correlation tables for article classification.

  

No problem. There are several similar scenarios in my project. For example, the product SKU operation is also batch, all of which are deleted and then inserted in batch.
if you want to achieve better, you can find out what is available in the database, compare it with what you passed in, and deal with the differentiated data. But it's troublesome.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e486bc-44009.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e486bc-44009.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?