function _webform_analysis_rows_select in Webform 5.2
Same name and namespace in other branches
- 5 components/select.inc \_webform_analysis_rows_select()
- 6.2 components/select.inc \_webform_analysis_rows_select()
Calculate and returns statistics about results for this component from all submission to this webform. The output of this function will be displayed under the "results" tab then "analysis".
Parameters
$component: An array of information describing the component, directly correlating to the webform_component database schema
$sids: An optional array of submission IDs (sid). If supplied, the analysis will be limited to these sids.
Return value
An array of data rows, each containing a statistic for this component's submissions.
File
- components/
select.inc, line 338 - Webform module multiple select component.
Code
function _webform_analysis_rows_select($component, $sids = array()) {
$options = _webform_select_options($component['extra']['items'], TRUE);
$placeholders = count($sids) ? array_fill(0, count($sids), "'%s'") : array();
$sidfilter = count($sids) ? " AND sid in (" . implode(",", $placeholders) . ")" : "";
$query = 'SELECT data, count(data) as datacount ' . ' FROM {webform_submitted_data} ' . ' WHERE nid = %d ' . ' AND cid = %d ' . " AND data != '0' AND data != '' {$sidfilter} " . ' GROUP BY data ';
$result = db_query($query, array_merge(array(
$component['nid'],
$component['cid'],
), $sids));
$rows = array();
while ($data = db_fetch_array($result)) {
if (isset($options[$data['data']])) {
$display_option = $options[$data['data']];
}
else {
$display_option = $data['data'];
}
$rows[] = array(
$display_option,
$data['datacount'],
);
}
return $rows;
}