GravityForms for WordPress is awesome. We are using it in a project but are running into something where we get stuck. GravityForms saves the "source_url" on submissions to determine where the submission came from. That's the basis of what we want: display submissions for page Y. We got that working using this query:

$responses = $wpdb->get_results( "SELECT * FROM wp_rg_lead WHERE source_url='".$source_url."'");

But now we want to sort and search on values the user have submitted when filling out the form. This data is saved in wp_rg_lead_details with the following structure:

|id|lead_id|form_id|field_number|value|

I want to sort on, and query a LIKE on the "value" of that table, matching a value from wp_rg_lead where source_url = x. But I'm stuck, I'm not sure how to set that up using joins or other MySQL functions.

It's important that the LIKE can extend to multiple values matching field_number x, y or z (in example).

SQL Fiddle: http://sqlfiddle.com/#!2/3352a/1

有帮助吗?

解决方案

Not sure exactly what you asking for, maybe this:

SELECT d.* FROM ( wp_rg_lead_details d
    JOIN wp_rg_lead l ON (d.lead_id = l.id))
 WHERE l.source_url = '$source_url' 
    AND d.value like '%$value%';

assuming there is a column id in your table wp_rg_lead

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top