There has always been a problem, basic, but still trying to figure it out. MySQL Read database storage ... It's a clang.
This post was last edited by xianglei1130 on 2013-03-04 14:50:06
Always have this problem, today is more hyper, send a post to discuss with you.
Self-knowledge of the general, so do not spray prawns.
is if there is a total record a table, there are various fields, SID title Content link ....
Then there is a personal record in table B, field: ID name sid (SID of Table A) to record the data that this person owns in table A.
Now that the problem arises, if the B-table "Zhang San" has 10 records of a, I was to put 10 SIDs with a symbol in the B table to the SID. or generate 10 records to deposit in table B?
Considering that the 1th method is to use explode to divide the SID of the B table, and then loop and then query a table to fetch the data. The 2nd method is to directly isolate all the records of the ID from the loop.
So what's the best way? From all aspects of the database program. In the next do not know how to explain, but also hope to teach ... Database Storage MySQL
------Solution--------------------
1, can be combined with a symbol (,) to deposit the SID of table B, query Find_in_set (A.SID,B.SID)
This situation requires b.sid large enough, if not 10, but 1000, 10,000.
2, each SID can be stored in a B, query A.sid=b.sid
It looks stupid, but it works.
3, the above scenario is assumed that A.SID is public, that is, multiple users can have the same a.sid. For example: friends, attention
If the A.SID is user-owned, such as posting
Then you should add a UID field to the A to record the attribution
------Solution--------------------
The second kind of simple, explode words, but also do a lot of their own operations