Closed (fixed)
Project:
Webform
Version:
6.x-2.7
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
27 Jul 2009 at 14:41 UTC
Updated:
7 Sep 2009 at 19:00 UTC
I would like to use "additional verification" to call the database and check to see if the sum of all submitted values for a specific field in my form has exceeded a set limit. I am trying to modify the code found here: http://drupal.org/node/342896 to do this, but apparently I don't know how to call for the data from the database.
My field name in the form is "adults" -- how would I structure the database query to get the data?
Thanks
Comments
Comment #1
ln282 commentedI know the cid of the data I need. I'm trying to use:
$count=array_sum(db_result(db_query("SELECT * FROM {webform_submissions} WHERE nid = %d AND cid =10", $node->nid)));
and it's not working-- is there something wrong with my syntax?
THanks for any help!
Comment #2
liam morlanddb_result returns only a single value: the first field of the first record of a query.
You may be able to get the sum you are looking for with SQL:
$count = db_result(db_query("SELECT sum(fieldname) FROM {webform_submissions} WHERE nid = %d AND cid = 10", $node->nid));On a related note, Webform has a function to grab entire submissions. Example use:
Comment #3
ezheidtmann commentedTry webform_submitted_data instead of webform_submissions.
Comment #4
ln282 commentedThanks!
I'm using this in the "additional validation" section:
And it works great. Adding the total from the form being currently submitted is key.
I'm going to add this to the comments on the additional validation code snippets page in the handbook.
Comment #5
liam morland