No nonsense, directly to everyone to paste the code, the code is very simple, are more common SQL statements, the specific content please see below.
CREATE TABLE ' Test_avatar ' (' uid ' int (one) unsigned NOT null default ' 0 ', ' Avatar ' varchar (255) NOT null default ', PRIMA RY KEY (' uid ')) Engine=myisam DEFAULT charset=utf8;insert into ' Test_avatar ' VALUES (1, './uploads/admin.jpg '); CREATE TABLE ' Test_pro ' (' id ' int (one) unsigned not null auto_increment, ' uid ' int (one) unsigned not null DEFAULT ' 0 ', ' nam E ' varchar (255) Not NULL default ", PRIMARY KEY (' id ')) engine=myisam default Charset=utf8;insert into ' Test_pro ' VALUES (1, 1, ' Product 1 '), (2,1, ' Product 2 '); CREATE TABLE ' Test_user ' (' id ' int (one) unsigned not null auto_increment, ' username ' varchar (a) NOT null DEFAULT ' ', ' tel ' Int (one) unsigned not NULL default ' 0 ', PRIMARY KEY (' id ')) engine=myisam the default Charset=utf8;insert into ' Test_user ' VA Lues (1, ' admin ', 110);
As in three tables: User Avatar table, product table, user table
How do I build relationships 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, ask the big God pointing
------to solve the idea----------------------
Model to establish the ProModelModel.class.php
Class Promodelmodel extends ViewModel {public $viewFields = Array (' Test_avatar ' =>array (' id ',...), ' Test_pror ' =>array (' id ',... ' _on ' = '), ' Test_pror ' =>array (' id ',... ' _on ' = ') ; }
The problems and solutions of SQL statements in thinkphp
I ask, in thinkphp, the data table has a field, the contents of the field is {1,2,3,4,5}
So how do you compare the ID value in the SQL statement to the content in the field?
------to solve the idea----------------------
Use fuzzy query.
$where = Array (' The field ' =>array (' like ', '% '. $ID. '%'));