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'];