Title: Display SQL based on input from WPForm
Last modified: July 23, 2023

---

# Display SQL based on input from WPForm

 *  Resolved [lwol2814](https://wordpress.org/support/users/lwol2814/)
 * (@lwol2814)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/display-sql-based-on-input-from-wpform/)
 *     ```wp-block-code
       Hi Guys, We are quite new to WordPress, but we managed to set up our website and connect it to our database. We have also succeeded in displaying data from our database using a global $wpdb; call. Now we want to take it a step further and display sql output based on user input
   
       I have set up a WPForm in WordPress with 2 main categories, Age Group and Risk Profile. In the Age Group category, there are 4 options the user can choose from
   
       Under 40 (if user chooses this i want the value 35 to be saved)
   
       Mellem 40 og 55 (If user chooses this i want the value 50 to be saved)
   
       Over 55 (If user chooses this i want the value 60 to be saved)
   
       Pensionist (If user chooses this i want the value 65 to be saved
   
       After that, the user has to put in his risk profile:
   
       Low risk(if the user chooses this i want the value “Low” to be saved”
   
       Medium risk(-||- “Medium”)
   
       High risk (-||- “High”)
   
       Then the user hits submit and then i want to display him the sql code. It could look like the below. So the users input should be passed to P.age_group and P.risk in the where clause.
   
       SELECT
       R.portfolio_id,
       P.portfolio_name,
       CONCAT(FORMAT((EXP(SUM(LOG(1 + R.return_value))) - 1) * 100, 2), '%') AS total_return_percentage
       FROM
       returns R
       INNER JOIN
       portfolios P ON R.portfolio_id = P.portfolio_id
       WHERE
       P.age_group = 35
       AND YEAR(R.date) = 2019
       and P.risk='Medium'
       GROUP BY
       R.portfolio_id,
       P.portfolio_name;
   
       How can i make that happen?
   
       Also as of right now we are only using wordpress, plugins & forms in the web. Meaning we have not downloaded anything. Do we need to download stuff in the long run or can all of it run through the website?
       ```
   

Viewing 1 replies (of 1 total)

 *  [Prashant Rai](https://wordpress.org/support/users/prashantrai/)
 * (@prashantrai)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/display-sql-based-on-input-from-wpform/#post-16919482)
 * Hey [@lwol2814](https://wordpress.org/support/users/lwol2814/) – Thanks for reaching
   out!
 * I apologize, getting the value from a dropdown field and passing it to a SQL 
   query would require some extended customization which falls outside of our scope
   for support. In case you’d like to look into custom development options, we highly
   recommend using[ Codeable](https://wpforms.com/docs/how-to-find-wpforms-custom-development-options-with-codeable/).
 * In case it helps, you can however take a look at [wpforms_process_complete](https://wpforms.com/developers/wpforms_process_complete/)
   action if you’re looking to get the submitted form data and then modify the query.
 * Thanks!

Viewing 1 replies (of 1 total)

The topic ‘Display SQL based on input from WPForm’ is closed to new replies.

 * ![](https://ps.w.org/wpforms-lite/assets/icon.svg?rev=3254748)
 * [WPForms - Easy Form Builder for WordPress - Contact Forms, Payment Forms, Surveys, & More](https://wordpress.org/plugins/wpforms-lite/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpforms-lite/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpforms-lite/)
 * [Active Topics](https://wordpress.org/support/plugin/wpforms-lite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpforms-lite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpforms-lite/reviews/)

## Tags

 * [forms](https://wordpress.org/support/topic-tag/forms/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [user input](https://wordpress.org/support/topic-tag/user-input/)

 * 1 reply
 * 2 participants
 * Last reply from: [Prashant Rai](https://wordpress.org/support/users/prashantrai/)
 * Last activity: [2 years, 10 months ago](https://wordpress.org/support/topic/display-sql-based-on-input-from-wpform/#post-16919482)
 * Status: resolved