Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('./wp-load.php');
- $form_id = 4;
- $form_answers = get_form_answers($form_id);
- $field_labels = get_field_labels($form_id);
- display_form($field_labels,$form_answers);
- function display_form($field_labels,$form_answers) {
- echo '<table border="1"><tr>';
- foreach($field_labels as $field_label)
- echo "<th>$field_label</th>";
- echo '</tr>';
- foreach($form_answers as $lead) {
- echo '<tr>';
- foreach(array_keys($field_labels) as $index)
- echo '<td>' . (!isset($lead[$index]) ? ' ' : $lead[$index]) . '</td>';
- echo '</tr>';
- }
- echo '</table>';
- }
- function get_form_answers($form_id) {
- global $wpdb;
- $sql = "
- SELECT
- ld.lead_id,
- ld.field_number,
- ld.value
- FROM
- wp_rg_lead_detail ld
- INNER JOIN wp_rg_lead l ON ld.lead_id = l.id
- WHERE
- ld.form_id = %d
- ORDER BY
- ld.lead_id,
- ld.field_number
- ";
- $sql = $wpdb->prepare($sql,$form_id);
- $results = $wpdb->get_results($sql, ARRAY_A);
- $form_answers = array();
- foreach($results as $row) {
- $row = (object)$row;
- $major_num = (int)$row->field_number;
- $minor_num = (int)(($row->field_number-$major_num)*10);
- $form_answers[$row->lead_id][$major_num][$minor_num] = $row->value;
- }
- foreach($form_answers as $i => $lead) {
- foreach($lead as $j => $form_answer) {
- $form_answers[$i][$j] = implode(' ',$form_answer);
- }
- }
- return $form_answers;
- }
- function get_field_labels($form_id) {
- global $wpdb;
- $sql = "SELECT display_meta FROM wp_rg_form_meta WHERE form_id = %d";
- $form = (object)unserialize($wpdb->get_var($wpdb->prepare($sql,$form_id)));
- foreach($form->fields as $field) {
- $field = (object)$field;
- $labels[$field->id] = $field->label;
- }
- return $labels;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement