Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Association query in ThinkPHP3.2

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to realize the association query in ThinkPHP3.2". In the daily operation, I believe that many people have doubts about how to realize the association query in ThinkPHP3.2. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to realize the association query in ThinkPHP3.2"! Next, please follow the editor to study!

CREATE TABLE `test_ avatar` (`uid` int (11) unsigned NOT NULL DEFAULT '0mm, `avatar` varchar (255i) NOT NULL DEFAULT'', PRIMARY KEY (`uid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;INSERT INTO `test_ avatar` VALUES (1Jie Zhe .UploadsAccord admin.jpg`); CREATE TABLE `test_ pro` (`id`int (11) unsigned NOT NULL AUTO_INCREMENT, `uid` int (11) unsigned NOT NULL DEFAULT '0mm, `name` varchar (255) NOT NULL DEFAULT'', PRIMARY KEY (`id`) ENGINE=MyISAM DEFAULT CHARSET=utf8) INSERT INTO `test_ pro` VALUES (1dint 1dhoe 'product 1'), (2dre 1dhoe' product 2'); CREATE TABLE `test_ user` (`id`int (11) unsigned NOT NULL AUTO_INCREMENT, `username`varchar (50) NOT NULL DEFAULT'', `tel`int (11) unsigned NOT NULL DEFAULT '0mm, PRIMARY KEY (`id`) ENGINE=MyISAM DEFAULT CHARSET=utf8;INSERT INTO `test_ user` VALUES

Such as the above three tables: user profile table, product table, user table

How to establish an association in the model?

Class ProModel extends RelationModel {protected $_ link=array ('Avatar'= > array (' mapping_type'= > self::HAS_ONE, 'class_name'= >' Avatar', 'foreign_key'= >' uid', 'mapping_fields'= >' avatar', 'as_fields'= >' avatar',),)}

Tried to use HAS_ONE, BELONGS_TO, HAS_MANY, MANY_TO_MANY are not good, ask God for advice

-solution ideas--

Establishing ProModelModel.class.php under Model

Class ProModelModel extends ViewModel {public $viewFields = array ('test_avatar'= > array (' id',...), 'test_pror'= > array (' id',...'_ on'= >'), 'test_pror'= > array (' id',...'_ on'= >'),);}

Problems related to SQL sentences in Thinkphp and their Solutions

Excuse me, in THINKPHP, there is a field in the data table. The content form of the field is {1meme2pence3pr 4pr 5}.

So how do you compare the ID value obtained in the SQL statement with the content in the field?

-solution ideas--

Use fuzzy query.

$where = array ('this field' = > array ('LIKE','%'. $ID. At this point, the study on "how to implement a relational query in ThinkPHP3.2" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report