2016 Bellingham Youth Regatta

Registered Participants

query($query);

// Create function to output data.
function output_data($fname, $lname, $boatclass, $sailnumber, $yachtclub) {
global $wpdb;
$wpdb->query( $wpdb->prepare(
“INSERT INTO temp_table_1 (lname, fname, boatclass, sailnumber, yachtclub) VALUES ( %s, %s, %s, %s, %s )”,
array(
$lname,
$fname,
$boatclass,
$sailnumber,
$yachtclub
)
));
}

//Set up our query to query a count of rows from the WordPress Gravity Forms table.

$query = “SELECT COUNT(d.id) FROM $usertable1 l INNER JOIN $usertable2 d ON l.id = d.lead_id WHERE l.form_id = $form_num AND l.status = ‘active’ ORDER BY lead_id, field_number”;

//Run the Query

$totalrecords = $wpdb->get_var($query);

//echo “Total Records = “, $totalrecords;

//Set up our query to query rows from the WordPress Gravity Forms table.

$query = “SELECT d.field_number, d.value FROM $usertable1 l INNER JOIN $usertable2 d ON l.id = d.lead_id WHERE l.form_id = $form_num AND l.status = ‘active’ ORDER BY lead_id, field_number”;

//Run the Query

$result = $wpdb->get_results($query);

if($result)
{
foreach($result as $key => $row)
{
$field_number = $row->field_number;
if ($field_number < $last_field_number or $recordcount == $totalrecords) { output_data($fname, $lname, $boatclass, $sailnumber, $yachtclub); //Reset the variables. $lname = ""; $fname = ""; $boatclass = ""; $sailnumber = ""; $yachtclub = ""; $last_field_number = 0; } else { $last_field_number = $field_number; } switch($field_number) { case 1.3: $fname = $row->value;
break;
case 1.6:
$lname = $row->value;
break;
case 27:
$boatclass = $row->value;
break;
case 28:
$sailnumber = $row->value;
break;
case 32:
$yachtclub = $row->value;
break;
default:
break;
}
$recordcount = $recordcount + 1;
//echo “Record Count: ” . $recordcount . “, ” . $lname;
if ($recordcount == $totalrecords)
{
output_data($fname, $lname, $boatclass, $sailnumber, $yachtclub);
}

}
}
//Set up our query to query rows from the WordPress temp_table_1 table.

$query = “SELECT
lname,
fname,
boatclass,
sailnumber,
yachtclub
FROM temp_table_1
ORDER BY boatclass, lname, fname”;

//Run the Query

$result = $wpdb->get_results($query);

if($result)
{
foreach($result as $key => $row)
{
$lname = $row->lname;
$fname = $row->fname;
$boatclass = $row->boatclass;
$sailnumber = $row->sailnumber;
$yachtclub = $row->yachtclub;
echo “

“;
}
}
$query = “DROP TABLE temp_table_1”;
$wpdb->query($query);
?>

Name Boat Class Sail # Yacht Club
” . $lname . “, ” . $fname . “ ” . $boatclass . “ ” . $sailnumber . “ ” . $yachtclub . “