Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7 manually querying webforms DB tables

I have a webform of 32 components and I am trying to create XML of the submitted data. The form has been filled and submitted just once.

$query  =   db_select('webform_submitted_data', 'wsd');
$query->join('webform_component', 'wc', 'wsd.cid = wc.cid');

$query->fields('wsd', array('nid', 'cid', 'data', 'sid'));
$query->fields('wc', array('form_key', 'name'));

$results    =   $query->execute()->fetchAll();

As you can see, I am performing a join between 2 tables in order to get the form_key for each filled webform component.

The problem is I get a lot more that 32 results - somehow the result is going badly wrong.

like image 208
sisko Avatar asked Apr 23 '26 18:04

sisko


1 Answers

If you are trying to get the submission data, you can use the webforms api to retrieve all submissions for a particular webform with the webform_get_submissions function. Then you can parse through the data for each submission to build your XML.

module_load_include('inc','webform','includes/webform.submissions');
$submissions = webform_get_submissions(array('nid'=>$webform_nid));

foreach ($submissions as $submission){
    foreach ($submission->data as $row=>$data){
        ...
    }
}
like image 199
mmiles Avatar answered Apr 26 '26 10:04

mmiles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!