Increment Database Value on Button Click

Hi all, I would like to develop a game counter in my Game.php. Imagine you see f.e. Score 2-0. 2 and 0 have an additional “+” Button. So inside the App each Player can increase his count +1 if he clicks the “+”-Button. There is no additional submit-Button. I would like to write into database and reload ScorePage f.e. to 2-1 or 3-1. I decided not to use JavaScript because if a match goes to 100 or 500 inbetween 3-5 hours and I loose internet connection or battery of mobile is empty all datas are gone. So each click on “+”-Button must be saved directly to database and reload page with new score or I re-open app and latest score appears. Can anybody help me doing that with via Query Builder?

You need to communicate this data change to the back-end. Since you don’t want to submit the forms (the usal HTML way), you will need JS for that.

Fortunatelly, Yii2 helps you do it in a transparent fashion, by using the PJax, which you can have a good read here: https://www.yiiframework.com/wiki/772/pjax-on-activeform-and-gridview-yii2

Basically it will use JS to submit this data to your back-end, where you will grab the requests, process and save the data in DB using your ActiveRecords. After that, you will respond with the updates on the screen.

Hi Bruno, thanks a lot for your quick and very helpful answer!
The link you recommended was 100% what I was looking for and without you I would have never found it. After creating the countries-database I used model generator and CRUD generator for countries. After replacing all content from CountriesController.php, index.php and _form.php from linked source “Create Countries” does what I was looking for. THANK YOU!

1 Like