Home > Backend Development > PHP Tutorial > php framework - thinkPHP Can this be written simpler?

php framework - thinkPHP Can this be written simpler?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:53:31
Original
900 people have browsed it

Looking at the tutorial, there is an activereocord example, but there are too few examples. I just want to explore a few more by myself. I want to ask, can this be written simply or more standardized?

Just search the data called Huang XX, and then put the Chinese score 1

<code>    public function activereocord2()
    {
        $use = D('classone');

        $id = $use->getByname('黄某某')['id'];   

        $condition ['id'] = $id;
        
        $use->where($condition)->setInc('语文',1);

        $this->oneRow($id);
    }
</code>
Copy after login
Copy after login

Reply content:

Looking at the tutorial, there is an activereocord example, but there are too few examples. I just want to explore a few more by myself. I want to ask, can this be written simply or more standardized?

Just search the data called Huang XX, and then put the Chinese score 1

<code>    public function activereocord2()
    {
        $use = D('classone');

        $id = $use->getByname('黄某某')['id'];   

        $condition ['id'] = $id;
        
        $use->where($condition)->setInc('语文',1);

        $this->oneRow($id);
    }
</code>
Copy after login
Copy after login

<code>$use = D('classone');
$use->where(array('name' => '黄某某'))->setInc('语文',1);</code>
Copy after login

Not reading the manual carefully

Isn’t it just a result set after get by name? Why do you need to check it again? . .

Get the ID through the name, and then use the ID field to modify the field...
Didn’t you go around in a circle...

Obviously it can be completed in one sentence, but it has to take so many detours. When writing this kind of database operation, first write down the SQL statement, and then consider using it in conjunction with the model syntax.

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template