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

php framework - thinkPHP Can this be written simpler?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-06 13:53:31909browse

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>

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>

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

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.

Statement:
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