2021 Holiday Tipping Poll Results

<?php $options = [ '0' => [ 'name' => 'Nothing', 'value' => 0 ], '1-250' => [ 'name' => 'Less than $250', 'value' => 0 ], '250-500' => [ 'name' => 'Around $250 to $500', 'value' => 0 ], '500-750' => [ 'name' => 'Around $500 to $750', 'value' => 0 ], '750-1000' => [ 'name' => 'Around $750 to $1,000', 'value' => 0 ], '1000-1500' => [ 'name' => 'Around $1,000 to $1,500', 'value' => 0 ], '1500-2000' => [ 'name' => 'Around $1,500 to $2,000', 'value' => 0 ], '2000-2500' => [ 'name' => 'Around $2,000 to $2,500', 'value' => 0 ], '2500-up' => [ 'name' => 'More than $2,500', 'value' => 0 ], ]; $results = [ 'own_in_doorman_building' => [ 'title' => 'Owners in doorman buildings:', 'options' => $options, 'total' => 0 ], 'own_in_non-doorman_building' => [ 'title' => 'Owners in non-doorman buildings:', 'options' => $options, 'total' => 0 ], 'rent_doorman_building' => [ 'title' => 'Renters in doorman buildings:', 'options' => $options, 'total' => 0 ], 'rent_non-doorman_building' => [ 'title' => 'Renters in non-doorman buildings:', 'options' => $options, 'total' => 0 ] ]; $total = 0; //get all fields from table with the holiday tipping nid $sql = 'SELECT * FROM {webform_submitted_data} WHERE nid = :nid'; $nid = '49386'; $result = db_query($sql, [':nid' => $nid]); $submissions = []; $key = 'sid'; while ($submission = $result->fetchObject()) { if ($submission->cid == '2') { $submissions[$submission->$key]['person_type'] = $submission->data; } if ($submission->cid == '3') { $submissions[$submission->$key]['amount'] = $submission->data; } } foreach ($submissions as $submission) { $person_type = $submission['person_type']; $amount = $submission['amount']; if(isset($results[$person_type]) && isset($results[$person_type]['options'][$amount])) { $results[$person_type]['options'][$amount]['value']++; $results[$person_type]['total']++; } } ?>

Holiday Tipping Poll

Holiday Tipping Poll
How much do you plan to tip the building staff this year?
<?php foreach ($results as $result) { print '
'; print '

'.$result['title'].'

'; if ($result['total'] == 0) { print 'No votes'; } else { foreach ($result['options'] as $option) { print '
'; $percentage = number_format(100 * ($option['value'] / $result['total']), 0); print '
' . $option['name'] . '
'; print '
'; print '
 
'; print '
'; print '
'.$percentage.'% ('.$option['value'].' '.format_plural($option['value'], 'vote', 'votes').')
'; print '
'; } } print '
(' . $result['total'] . ' total ' . format_plural($result['total'], 'vote', 'votes') . ')
'; print '
'; $total += $result['total']; } ?>
[ <?php print $total ?> total votes ]