I need to populate every field on my form, even those fields that don't have any values submitted so that each record has a consistent number of rows in the database. What is the best way to do this?
I need to populate every field on my form, even those fields that don't have any values submitted so that each record has a consistent number of rows in the database. What is the best way to do this?
This is a strange request, it is possible but you would have to do so by writing some custom PHP to populate the field values if the field is empty. How comfortable are you with PHP and working with WordPress API hooks?
Not that familiar with hooks, but I am comfortable with PHP. And maybe I'm approaching my problem from the wrong direction.
What I'm trying to accomplish is to publicly display the form submissions in a row format. I've written a custom query that GROUP_CONCATs the value fields from one submission into one field and then I'm using PHP to explode that for my display. The problem I'm running into is that submissions have varying numbers of fields depending on what was submitted. I thought if I forced empty fields to have data, then I'd get consistent results when I'm building my rows.
Is there a better way to approach the problem/need I'm having?
Here is an example of my custom query:
$querystr = "
SELECT wp_rg_lead.date_created,
wp_rg_lead_detail.lead_id,
wp_rg_lead_detail.form_id,
GROUP_CONCAT(wp_rg_lead_detail.value ORDER BY wp_rg_lead_detail.field_number) AS resultsrow,
wp_rg_lead.source_url,
wp_rg_lead.user_agent
FROM wp_rg_lead_detail INNER JOIN wp_rg_lead ON wp_rg_lead_detail.lead_id = wp_rg_lead.id
WHERE ( wp_rg_lead_detail.form_id = '3' )
GROUP BY wp_rg_lead_detail.lead_id
";
I believe I've solved my situation using a nested foreach statement. I've set up 2 queries, one that grabs the rows with lead_id, and one that loops through all rows where the the lead_id from query 1 matches the lead_id from query 2. This is probably a much better solution and doesn't require me to insert rows where there is no data.
_________________________________________
foreach ($myResultRows as $row):
foreach ($myResultRows2 as $row2):
if ($row->lead_id == $row2->lead_id ) {
echo $row2->field_number . " | " . $row2->value . " | ";
}
endforeach;
echo "
";
endforeach;
Glad you figured it our Brian!