In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to use the find method of thinkphp". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "how to use the find method of thinkphp" can help you solve the problem.
In thinkphp, the find method is used to get a row of records that meet the conditions in the data table. This function can only return a row of records. If you get multiple records that meet the conditions, you will return the first record. The result is an array, and the key of the array corresponds to the field in sql.
This article operating environment: Windows10 system, ThinkPHP3.2 version, Dell G3 computer.
How to use the find method of thinkphp
The ThinkPHP find () method is similar to the usage of select (), except that find () always queries only one piece of data, that is, the system automatically adds a LIMIT 1 restriction.
When confirming that the data record queried can only be one record, it is recommended to use the find () method to query, such as user login account detection:
Public function chekUser () {header ("Content-Type:text/html; charset=utf-8"); $Dao = M ("User"); / / construct query conditions $condition ['username'] =' Admin'; $condition ['password'] = MD5 (' 123456'); / / query data $list = $Dao- > where ($condition)-> find (); if ($list) {echo 'account is correct' } else {echo 'account / password error';}}
Another difference from select () is that find () returns an one-dimensional array, which can output the value of the array unit directly in the template without having to loop through tags such as volist:
{$list ['username']} find () primary key query
When the conditional parameter of the find () query is the table primary key, you can write the parameter directly into the method, such as:
$Dao = M ("User"); $list = $Dao- > find (1)
The primary key of the user table is uid, and this example will query the data of uid=1, which is one of the ActiveRecords schema implementations, concise and intuitive.
The find method returns a row of records, and the result is an array. The key of the array corresponds to the field in sql, assuming:
$res=$model- > find (filed= "a dint bje c")
To get the value of an in the result:
This is the end of $res ["a"] on "how to use the find method of thinkphp". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.