Increment field - based on radio box or dropdown choice

hugocosta 28 Jul, 2014
Hi

How can i increment a table field (int), based on radiobutton chosen?
I´m trying to implement voting system in my form.

Example: If user pick a radio button (or dropdown) choise, it will increment a field (int) in the table of database based on that choice.

can you help me?
Thanks
GreyHead 28 Jul, 2014
Hi hugocosta,

You'd have to do that with Custom Code. It would be something like this:
$db = JFactory::getDBO();
$query = "
  UPDATE  `#__`
    SET `some_column` = `some_column` + 1
    WHERE `xxx` = 'zzz' ;
";
$db->setQuery($query);
$db->execute();

I can't tell from your post what the WHERE clause should be - I guess you have some way to identify the record to be updated.

Bob
hugocosta 28 Jul, 2014
Hi,
Thanks for your help, Bob.

For example: I have a radio box with 3 choices:
Good, Suficient, Bad.
In my table, I have 3 fields (int): totalgood, totalsuficient, totalbad.

In the form, if user pick the Good radio button choice, it will increment totalgood field in table, with +1.
In the code, how can i connect the user´s radio button chosen with the respective table´s field increment?

Is this possible wiht the code you gave me?
Very thanks,
Hugo Costa
GreyHead 28 Jul, 2014
Hi Hugo,

Might it be simpler just to save the form results with each entry in a new record, then look up the totals when you need them?

With your description I'm not clear what the database table looks like? Does it just have one record?

Bob
hugocosta 28 Jul, 2014
Hi, Bob

I have a table called 'ideas'. I have a form that alow users inserting a new idea.
Each record of table is one idea. In this table, I have several fields (name, description, date,...) and i have 3 int fields (totalgood, totalsuficient, totalbad).

After user´s inserting, i have the chronoconnectivity to see and edit the records (ideas). I have a second form that alow user to editing the idea. In this form I have a radio's button group with 3 choices (Good, Suficient, Bad). I would like to, when user pick the choice "Good", it will update and increment that record (idea) in the field 'totalgood' with +1. That is the voting system that I try to implement with Chronoforms.

Can you help me?
Thanks,
Hugo Costa
GreyHead 28 Jul, 2014
Hi Hugo,

That's fine, the code that I posted will do that - the WHERE clause needs to identify the record for the current idea.

Bob
This topic is locked and no more replies can be posted.