Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
356 views
in Plugins by
Hello there.

I'm coding a new plugin. I created a new field for users in the userpoints table on my q2a site. I have to update this area for each scoring, according to the score obtained. This field will work independently from the points field. Because I will reset this field as a result of a completed task and start scoring from scratch.

How can I do that?

(I used Google Translate for translation. Sorry for the spelling mistakes.)
Q2A version: 1.8
by
+2
If that field will work independently from the points field, then why don't you create a new table instead?

If you create a new column (field), functions like "SELECT * FROM ^userpoints " will have an extra value in the result array and may cause errors somewhere else.

"Because I will reset this field as a result of a completed task and start scoring from scratch." --> It's hard to guess the deep meaning here.

You'd better ask with a registered account because you may need to provide with more information.

Your main question  "How can I do that?" - Do what?
by
I could not express myself fully.
I created a field called marketpoints in the userpoints table. What I want to do is, when the user gets a score, add the score to that area.
However, for each point the user gets, the points.php file recalculates all points of the user and updates the database.
Is there a function that works for each score? How do I calculate and add each score to the database?

My goal: To reward the user with the points the user receives and to deduct the points that the user receives from the market points.
by
+1
You may need some kind of an event module  ( https://docs.question2answer.org/plugins/modules-event/ ), but I can't find such an event module  that is suitable for your needs.

About database management, you don't need to, and should not add an extra field to those core existing table. You can create a new table with two columns like userid and market points. You can replicate how points.php works to update your marketpoint table. For example, when user posts some thing (q_post', 'a_post' or 'c_post' events) then do some script to update the mysql table.

An example is here https://www.question2answer.org/qa/87268/update-another-database-table-when-a-question-is-created

About your goal, I think it's similar to a Q2A Badge plugin, maybe it's helpful for your ideas.

Please log in or register to answer this question.

...