Link how to set click once. Database hits plus 1

Source: Internet
Author: User

Click on a link to the database should be the corresponding number of Access + 1, you can only write a method in the current page with JS to access

To get the parameters of the link to click with the AJAX parameters to the controller, in the controller to get the parameters passed over

Find out if there is a record in the database, if there is a field +1 that can be obtained after this data

<a href= ' <?=url::to ([' AAA ', ' ID ' + 1])?> ' class = ' Count_add ' > click </a>

<script>
$ (funcation () {
$ (document). On (' click ', '. Count_add ', function () {
var id = $ (this). attr (' href ');
Id=id.substr (id.indexof ("=") +1,id.length-1);
$.get (' <?=url::to ([' countadd ')];? > ', {' id ': id}, function () {
});
});
});
</script>

Controller

Public Function Actioncountadd ()
{
$id = Intval ($_get[' id ");
$bucket = Bucket::find ()->andwhere ([' user_id ' = ' = $this->_userid, ' id ' = + $id])->one ();
if ($bucket) {
$bucket->count + = 1;
$bucket->save ();
}
return $this->redirect (' index ');
}

Link how to set click once. Database hits plus 1

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.