Home  >  Article  >  Backend Development  >  ThinkPHP+Mysql关联模型求助

ThinkPHP+Mysql关联模型求助

WBOY
WBOYOriginal
2016-06-06 20:28:141142browse

有两张表,userpic表是图片上传的表,dynamic表是用户发布的动态列表,dynamic里面的userpic_id字段的各个值对应userpic表的id
dynamic表里的userpic_id字段有字符串:5,4,3,1,2

1.怎样做才能把字符串里的各个id与userpic表的id关联起来呢?
2.是怎样的关联,一对多还是多对多?

ThinkPHP+Mysql关联模型求助

ThinkPHP+Mysql关联模型求助

回复内容:

有两张表,userpic表是图片上传的表,dynamic表是用户发布的动态列表,dynamic里面的userpic_id字段的各个值对应userpic表的id
dynamic表里的userpic_id字段有字符串:5,4,3,1,2

1.怎样做才能把字符串里的各个id与userpic表的id关联起来呢?
2.是怎样的关联,一对多还是多对多?

ThinkPHP+Mysql关联模型求助

ThinkPHP+Mysql关联模型求助

查询表的时候直接where uid in 不就行了,一对多还是多对多看你项目需求了。但多对多管理起来比较麻烦。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn