2

Drupal 7 Webform 7.x-4.0-alpha6

I have two webforms with two fields in common; "name" and "e-mail".

I want to display "name" and "e-mail" from all webform submissions in one overview table.

The webform submission data fields available to views use static references to the component id of an individual webform field. Thus, if the component id of webform fields were matching across webforms, I could use a view. But this is not the case.

So one strategy, as far as I can see, is to use the database abstraction API of Drupal 7.

I select the submitted_data table.

    //select table
    $query = db_select('webform_submitted_data', 'd');

Now I join with the component table. This will allow me to reference the form_key instead of the component id. I tie the tables together by the component id.

    //combine tables
    $query->join('webform_component', 'c', 'd.cid = c.cid');

Now I select the fields of my query. I want both the "name" and "email" field. If I only want, say, the "name" field, this will work, I think:

    //select fields
    $query
     ->fields('d', array('data'))
     ->condition('form_key', 'name', '=');

However, since both "name" and "email" values are part of the data column, I cannot include both in the table, since when I build the rows of my table, I can only reference the field by the "data" column.

    //select fields
    $query
    ->fields('d', array('data'))
    ->condition('form_key', 'name', '=')
    ->fields('d', array('data'))
    ->condition('form_key', 'email', '=');

    $results = $query->execute();

    $rows = array();
    foreach ($results as $submission) {
     $rows[] = array(
      $submission->data,
      $submission->data, //how to distinguish between name and email?
     );
    }

Has anyone got an idea or tips on how to solve this? Specifically, how can I display two or more values from the data column of the webform_submitted_data table across multiple webforms in one table?

protected by kiamlaluno Jun 1 '16 at 3:35

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Browse other questions tagged or ask your own question.