Thinkphp extracts arrays from the obtained result set

Source: Internet
Author: User
Thinkphp has one day of data in the obtained result set. how can I extract the data and convert it to an array? Thinkphpphp

Thinkphp has one day of data in the obtained result set. how can I extract the data and convert it to an array?

Reply content:
The ThinkPHP find method queries a data record. the find () ThinkPHP find () method is similar to the select () method. In contrast, the find () method queries only one data record, that is, the system automatically adds the LIMIT 1 LIMIT. When you confirm that the queried data record can only be one record, we recommend that you use the find () method for query. for example, the user logon account detection: public function chekUser () {header ("Content-Type: text/html; charset = utf-8 "); $ Dao = M (" User "); // Construct the query condition $ condition ['username'] = 'admin '; $ condition ['password'] = MD5 ('20140901'); // query data $ list = $ Dao-> where ($ condition)-> find (); if ($ list) {echo 'account right';} another difference between else {echo 'account/password error';} and select () is that find () the returned result is a one-dimensional array. you can directly output the value of the array unit in the template without the use of tags such as volist for loop output :{ $ List ['username']} find () primary key query when the condition parameter of the find () query is the table primary key, you can directly write the parameter to the method, for example: $ Dao = M ("User"); $ list = $ Dao-> find (1); the user table's primary key is uid. In this example, data with uid = 1 is queried, this is one of the implementations of the ActiveRecords mode, which is concise and intuitive.

For example, $ list = $ Base-> where ("id = '". $ id. "'")-> select ();
Echo $ list ['title'];

Extracted array:
$ List = $ Base-> where ("id = '". $ id. "'")-> select ();
Change
$ List = $ Base-> where ("id = '". $ id. "'")-> find ();
Select is a two-dimensional array.
If you are sure that there is only one record, use find. of course you can use select. it's just a little bit of a feeling of getting rid of your pants and farting. if you use select, echo $ list [0] ['title'];

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.