Title: Dropdown Select using DB data
Last modified: August 7, 2023

---

# Dropdown Select using DB data

 *  Resolved [EmperorFPM](https://wordpress.org/support/users/emperorfpm/)
 * (@emperorfpm)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/)
 * I just don’t get it. The “test data source” returns correct results. No errors
   in console or debug but will not show up using this:
 * [select vehicleyears][cf7-recordset id=”cf7-recordset-284″ type=”database” query
   =”SELECT DISTINCT year FROM car_db”][cf7-link-field recordset=”cf7-recordset-
   284″ field=”vehicleyears” value=””]
 * Any help would be appreciated, testing this on local currently and have the CF7
   Smart Grid extension in use.

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/dropdown-select-using-db-data/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/dropdown-select-using-db-data/page/2/?output_format=md)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16954358)
 * Hello [@emperorfpm](https://wordpress.org/support/users/emperorfpm/)
 * Thank you very much for using our plugin. The [cf7-link-field] tag requires you
   to enter the value and text attributes with the columns in the recordset tag.
 * So, the form structure would be:
 *     ```wp-block-code
       [select vehicleyears]
       [cf7-recordset id="cf7-recordset-284" type="database" query="SELECT DISTINCT year FROM car_db"]
       [cf7-link-field recordset="cf7-recordset-284" field="vehicleyears" value="year" text="year"]
       ```
   
 * I’m assuming your query is correct, and the car_db table is in the same website’s
   database.
 * Best regards.
 *  Thread Starter [EmperorFPM](https://wordpress.org/support/users/emperorfpm/)
 * (@emperorfpm)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16954435)
 * Thanks for the reply, it was actually the value=”year” and text=”year” that were
   missing and that is why the data was there but wouldn’t display. Didn’t realize
   it need to match the DB query and not the field.
 * Here is complete working:
 * Car Years
 * [select caryears select2]
 * [cf7-recordset id=”car-years” type=”database” query=”SELECT DISTINCT year FROM
   car_db”]
 * [cf7-link-field recordset=”car-years” field=”caryears” value=”year” text=”year”]
 * And now I’m trying to get the year to create a database query so I can get the‘
   make’ of cars from the ‘year’ entered by user
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16954442)
 * Hello [@emperorfpm](https://wordpress.org/support/users/emperorfpm/)
 * If year and make are columns in the same car_db table, you don’t need another[
   cf7-recordset] tag, only edit the query and insert a second [cf7-link-field] 
   tag, as follows:
 *     ```wp-block-code
       [select caryears select2]
       [select carmakes select2]
   
       [cf7-recordset id="car-years" type="database" query="SELECT DISTINCT year, make FROM car_db"]
   
       [cf7-link-field recordset="car-years" field="caryears" value="year" text="year"]
       [cf7-link-field recordset="car-years" field="carmakes" value="make" text="make" condition="record['year'] == {field.caryears}"]
       ```
   
 * Best regards.
 *  Thread Starter [EmperorFPM](https://wordpress.org/support/users/emperorfpm/)
 * (@emperorfpm)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16954460)
 * That is super helpful to know, thank you.
 * This == {field.caryears}”] isn’t being seen, I tried to span it and use a do_shortcode
   but those didn’t work
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16954463)
 * Hello [@emperorfpm](https://wordpress.org/support/users/emperorfpm/)
 * I’m sorry, I don’t know what you mean with:
 * >> This `== {field.caryears}"]` isn’t being seen, I tried to span it and use 
   a do_shortcode but those didn’t work
 * Best regards.
 *  Thread Starter [EmperorFPM](https://wordpress.org/support/users/emperorfpm/)
 * (@emperorfpm)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16954467)
 * it’s showing up on the page and not being executed. I’ve also just discovered
   another issue. I’m trying to have a user select a Year and then the Models of
   Cars from that Year will populate the next Select and then from the choice of
   Models the next Select (Makes) is populated.
 * Right now using this:
 * Year of Car [select caryears select2]
 * Make of Car [select carmakes select2]
 * Model of Car [select carmodels select2]
 * [cf7-recordset id=”car-years” type=”database” query=”SELECT DISTINCT year, make,
   model FROM car_db”]
 * [cf7-link-field recordset=”car-years” field=”caryears” value=”year” text=”year”]
 * [cf7-link-field recordset=”car-years” field=”carmakes” value=”make” text=”make”
   condition=”record[‘year’] == {field.caryears}”]
 * [cf7-link-field recordset=”car-years” field=”carmodels” value=”model” text=”model”
   condition=”record[‘make’] == {field.carmakes}”]
 * All of the models from every make of car is being shown in the last select field.
 * Do I need to do separate query to keep them isolated to the previous query results?
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16954472)
 * Hello [@emperorfpm](https://wordpress.org/support/users/emperorfpm/)
 * I see what is happening, I’m inserting the symbols [ and ] encoded, but the WordPress
   editor is transforming them again into [].
 * It is not possible to include additional [] symbols into shortcode attributes.
 * So, to avoid the editor replacing the symbols again, I’ll include the code as
   an image:
 * ![](https://i0.wp.com/resources.developers4web.com/cff/tmp/2023/08/07/screenshot.
   png?ssl=1)
 * Please, look as I used two conditions in the last [cf7-link-field] tag.
 * Best regards.
 *  Thread Starter [EmperorFPM](https://wordpress.org/support/users/emperorfpm/)
 * (@emperorfpm)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16954522)
 * I’ll say your effort and support get you 5+ stars and I’ll make sure to review
   the plug-in.
 * That said it still doesn’t work 🙁
 * I’ll keep working on it but not sure what to even look at next.
 * If I find a solution, I’ll update, if you have any other ideas I’d be appreciative.
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16954525)
 * Hello [@emperorfpm](https://wordpress.org/support/users/emperorfpm/)
 * Could you please indicate the URL to the page that contains the form to check
   your code in action?
 * Best regards.
 *  Thread Starter [EmperorFPM](https://wordpress.org/support/users/emperorfpm/)
 * (@emperorfpm)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16957332)
 * I ran out of time yesterday but here is live URL for the form
 * [https://financialexaminer.com/test-car-choice/](https://financialexaminer.com/test-car-choice/)
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16957405)
 * Hello [@emperorfpm](https://wordpress.org/support/users/emperorfpm/)
 * Thank you very much for sending me the URL.
 * Please, look at the following screenshot:
 * ![](https://i0.wp.com/resources.developers4web.com/cff/tmp/2023/08/07/screenshot2.
   png?ssl=1)
 * As you can see, the shortcodes for the [cf7-link-field] fields are broken. That
   happens if you include the “[” or “]” symbols as part of their attributes’ values.
 * Pay attention to the following image where these symbols are encoded:
 * ![](https://i0.wp.com/resources.developers4web.com/cff/tmp/2023/08/07/screenshot.
   png?ssl=1)
 * When you insert the fields through the plugin interface, it encodes the symbols
   for you.
 * Best regards.
 *  Thread Starter [EmperorFPM](https://wordpress.org/support/users/emperorfpm/)
 * (@emperorfpm)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16957714)
 * I’ll try a couple more things.
    -  This reply was modified 2 years, 10 months ago by [EmperorFPM](https://wordpress.org/support/users/emperorfpm/).
 *  Thread Starter [EmperorFPM](https://wordpress.org/support/users/emperorfpm/)
 * (@emperorfpm)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16957766)
 * Copied verbatim from the image – no luck
 * Used a fresh basic WP install with only CF7 and this – no luck
 * Not sure what else I can, seems like a really good idea for a plugin and I wish
   I could sort it out.
 * Thanks for all your help so far
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16958847)
 * Hello [@emperorfpm](https://wordpress.org/support/users/emperorfpm/)
 * Could you please try the alternative notation?
 *     ```wp-block-code
       Year of Car [select caryears select2]
   
       Make of Car [select carmakes select2]
   
       Model of Car [select carmodels select2]
   
       [cf7-recordset id="car-years" type="database" query="SELECT DISTINCT year, make, model FROM car_db"]
   
       [cf7-link-field recordset="car-years" field="caryears" value="year" text="year"]
   
       [cf7-link-field recordset="car-years" field="carmakes" value="make" text="make" condition="record.year == '{field.caryears}'"]
   
       [cf7-link-field recordset="car-years" field="carmodels" value="model" text="model" condition="record.make == '{field.carmakes}'"]
       ```
   
 * Best regards.
 *  Thread Starter [EmperorFPM](https://wordpress.org/support/users/emperorfpm/)
 * (@emperorfpm)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/#post-16961091)
 * 1000 STARS!!
 * That did it. It now works as I knew it could.
 * Thanks for your help.

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/dropdown-select-using-db-data/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/dropdown-select-using-db-data/page/2/?output_format=md)

The topic ‘Dropdown Select using DB data’ is closed to new replies.

 * ![](https://ps.w.org/cf7-data-source/assets/icon-256x256.gif?rev=2508392)
 * [Data Source for Contact Form 7](https://wordpress.org/plugins/cf7-data-source/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cf7-data-source/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cf7-data-source/)
 * [Active Topics](https://wordpress.org/support/plugin/cf7-data-source/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cf7-data-source/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cf7-data-source/reviews/)

 * 16 replies
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [2 years, 10 months ago](https://wordpress.org/support/topic/dropdown-select-using-db-data/page/2/#post-16961104)
 * Status: resolved