An error occurred while adding 1 to the MySql field.

Source: Internet
Author: User
I found a problem many days ago. I thought it was my machine problem. I still cannot solve the problem after I uploaded my ECs instance. Hope you can help me ~ First, my blog post has a Look field in Mysql. Every time I view this blog, I add 1 to the original value. But the problem is that I click to view it every time... I found a problem many days ago. I thought it was my machine problem. I still cannot solve the problem after I uploaded my ECs instance. Hope you can help me ~
First, my blog post has a Look field in Mysql. Each time I view this blog, this field is added to the original value by 1, but the problem is that I always add 2 to the original value every time I click to view it. This is really confusing to me. Check the source code.

public function viewBlog(){        $_sql='SELECT *            FROM blog            WHERE id='.$this->_id.' AND verify=1';        $_sqlView='UPDATE blog SET `look`=`look`+1 WHERE id='.$this->_id;        parent::aud($_sqlView);        return parent::getOne($_sql);    }    

This is the source code in the Model.

private function viewBlog(){            $this->_model->_id=Tool::checkInt(@$_GET['id']);            $_oneBlog=$this->_model->viewBlog();            $this->_tpl->assign('oneBlog',$_oneBlog);        

This is the source code snippet of the controller. It has been confirmed that the viewBlog () function is only executed once, what's more strange is that if I click a comment (the comment and view are only one more # anchor is located in the comment box), its look value will be increased by 3, then, click View or comment on it to add 1 to it ......
Please tell your blog that this is my blog address, not the access traffic ~~~

Reply content:

I found a problem many days ago. I thought it was my machine problem. I still cannot solve the problem after I uploaded my ECs instance. Hope you can help me ~
First, my blog post has a Look field in Mysql. Each time I view this blog, this field is added to the original value by 1, but the problem is that I always add 2 to the original value every time I click to view it. This is really confusing to me. Check the source code.

public function viewBlog(){        $_sql='SELECT *            FROM blog            WHERE id='.$this->_id.' AND verify=1';        $_sqlView='UPDATE blog SET `look`=`look`+1 WHERE id='.$this->_id;        parent::aud($_sqlView);        return parent::getOne($_sql);    }    

This is the source code in the Model.

private function viewBlog(){            $this->_model->_id=Tool::checkInt(@$_GET['id']);            $_oneBlog=$this->_model->viewBlog();            $this->_tpl->assign('oneBlog',$_oneBlog);        

This is the source code snippet of the controller. It has been confirmed that the viewBlog () function is only executed once, what's more strange is that if I click a comment (the comment and view are only one more # anchor is located in the comment box), its look value will be increased by 3, then, click View or comment on it to add 1 to it ......
Please tell your blog that this is my blog address, not the access traffic ~~~

Do not directly store the data in the database first, test it.look=look+ 1 is there a problem here. Check if the access is actually performed once.

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.