Share ThinkPHP3.2's associated query solution and thinkphp3.2's ideas. I will share ThinkPHP3.2's related query solution ideas. thinkphp3.2 is not nonsense and I will directly post code to you. the code is very simple and is a common SQL statement, for details, refer to the related query solutions and ThinkPHP3.2 ideas in thinkphp3.2.
The code is simple. it is a common SQL statement. for details, see the following.
Create table 'test _ avatar '('uid' int (11) unsigned not null default '0', 'Avatar' varchar (255) not null default '', primary key ('uid') ENGINE = MyISAM default charset = utf8; insert into 'test _ avatar 'VALUES (1 ,'. /Uploads/admin.jpg '); create table 'test _ PRO' ('id' int (11) unsigned not null AUTO_INCREMENT, 'uid' int (11) unsigned not null default '0', 'name' varchar (255) not null default '', primary key ('id') ENGINE = MyISAM default charset = utf8; insert into 'test _ Pro' VALUES (, 'product 1'), (, '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 '0', primary key ('id') ENGINE = MyISAM default charset = utf8; insert into 'test _ user' VALUES (1, 'admin ', 110 );
For example, there are three tables: User profile table, product table, and user table.
How to establish 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', ), )}
I tried HAS_ONE, BELONGS_TO, has_detail, and many_to_detail.
------ Solution ----------------------
Create 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 statements in Thinkphp and solutions
In THINKPHP, the data table contains a field in the form of {1, 2, 3, 4, 5}
So how can I compare the obtained ID value with the content in the field in the SQL statement?
------ Solution ----------------------
Use fuzzy search
$ Where = array ('field '=> array ('like',' % '. $ ID.' % '));
The code is simple. it is a common SQL statement. for details, see the following...