Home  >  Article  >  PHP Framework  >  How to query data through table connection in yii framework

How to query data through table connection in yii framework

王林
王林Original
2020-02-19 11:44:582168browse

How to query data through table connection in yii framework

First create the database and data table, as shown in the figure below (partial screenshot):

Database:

How to query data through table connection in yii framework

Data table:

(Related tutorial recommendations: yii framework)

jf_stu:

How to query data through table connection in yii framework

##js_class:

How to query data through table connection in yii framework

js_school:

How to query data through table connection in yii framework

js_record:

How to query data through table connection in yii framework

Example:

//表连接,查询出学生、班级、校区、记录表的所有数据
		$data=Jf_record::find()
		->join('join','jf_stu','jf_record.sid=jf_stu.sid')
		->join('join','jf_class','jf_stu.cid=jf_class.cid')
		->join('join','jf_school','jf_class.xid=jf_school.xid')
		->select('*')
		->where(['jf_record.re_id'=>$re_id])
		->asArray()
		->one();
		echo $data[&#39;sname&#39;].&#39;<br>&#39;;
		echo $data[&#39;sex&#39;].&#39;<br>&#39;;
		echo $data[&#39;rtime&#39;].&#39;<br>&#39;;
		echo $data[&#39;cname&#39;].&#39;<br>&#39;;
		echo $data[&#39;school&#39;].&#39;<br>&#39;;
		die;

Output result:


How to query data through table connection in yii framework

For more programming-related content, please pay attention to the

Programming Introduction column on the php Chinese website!

The above is the detailed content of How to query data through table connection in yii framework. For more information, please follow other related articles on the PHP Chinese website!

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