thinkphp table Query and data export Method Example _php instance

Source: Internet
Author: User

This paper illustrates the method of thinkphp query and data export. Share to everyone for your reference, specific as follows:

This is the new work of the lab is about to unfold, we through the Laboratory website Association to Hang Electric OJ, freshmen will their hang electricity user name in the laboratory site submitted, the site will be through the web crawler to hang electric OJ above data capture to the laboratory database.

Now all I have to do is to combine the freshman table with the freshman OJ datasheet. The lab website is developed using the thinkphp framework. So based on previous work experience. The problem was solved quickly.

Now share with you.

Thinkphp's expansion classes are all placed under the Org directory, and can be used in advanced attempt mode or not using the import () function call to view the table.

Do not use Advanced view mode.
//Two sheets, userinfo and oj_data
//export student information
$user = $userinfo->table (' lab_userinfo,lab_oj_data ')
-> Field (
' Lab_userinfo.userid,
lab_userinfo.truename,
lab_userinfo.year,
lab_userinfo.sex,
Lab_userinfo.subject,
Lab_userinfo.email,
lab_userinfo.date,
lab_oj_data.username as username,
lab_oj_data.solved as solved,
lab_oj_data. Submit as Submit,
Lab_oj_data. AC as AC ')
->where (' Lab_userinfo.userid=lab_oj_data.userid and Pass=0 ')->order (' lab_oj_data.solved desc ') )
->select ();

It is to be noted that. The data table prefix is set in the configuration of the thinkphp framework, and it is important to note that the prefix is automatically added in addition to the model call, and the others are manually appended.

As you've learned about SQL, SQL statements allow table aliases to be used.

So when we use the table, we can alias it.

Table (' Lab_userinfo userinfo,lab_oj_data data ');

This is not the same as the SQL statement when you alias the table without as.

Then the data export problem, can refer to the previous article "PHP implementation of export Excel data Class Library usage Example"

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.