Hello,
I am trying to create a report that is run daily via cron which will list all entries for that day.
I am creating from plain old PHP (ie: i'm not using wordpress/gravity forms functions whatsoever).
All is well, I can get all the data, but how do I get the NAMES of the fields?
How do I know what each 'field_number' means?
Do I need to look at a meta table and unserialize some text into a PHP array?
$result = mysql_query("
SELECT wp_rg_lead.id,
wp_rg_lead.form_id,
wp_rg_lead.post_id,
wp_rg_lead.date_created,
wp_rg_lead.ip,
wp_rg_lead.source_url,
wp_rg_lead.user_agent ,
wp_rg_lead_detail.field_number,
wp_rg_lead_detail.value,
wp_rg_lead_detail_long.value as long_value
FROM wp_rg_lead LEFT JOIN wp_rg_lead_detail ON wp_rg_lead.id = wp_rg_lead_detail.lead_id
LEFT JOIN wp_rg_lead_detail_long ON wp_rg_lead_detail.id = wp_rg_lead_detail_long.lead_detail_id
ORDER BY date_created DESC; ");
echo "<table>";
// build leads into array
$leads = array();
while ($row = mysql_fetch_assoc($result)) {
// if the lead isnt in the array, then add it
if (!isset($leads[$row['id']])) {
$leads[$row['id']] = $row;
}
// store the data and field
$leads[$row['id']]['fields'][$row['field_number']] = $row['value'];
}
$doneHeader = false;
foreach ($leads as $id => $lead) {
// if we haven't done the table header, then do it
if (!$doneHeader) {
echo "<tr>";
foreach ($lead as $name => $value)
echo "<th>{$name}</th>";
echo "</tr>";
$doneHeader = true;
}
echo "<tr>";
foreach ($lead as $name => $value) {
if ($name == 'fields') {
echo "<td>";
foreach ($value as $fid => $fv) {
echo "{$fv}<br>";
}
echo "</td>";
} else {
echo "<td>{$value}</td>";
}
}
echo "</tr>";
}
echo "</table>";