Title: Can&#8217;t generate code snippet data
Last modified: October 19, 2023

---

# Can’t generate code snippet data

 *  Resolved [danielleal04](https://wordpress.org/support/users/danielleal04/)
 * (@danielleal04)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/cant-generate-code-snippet-data/)
 * I am trying to populate a drop down with data from SQL.
 * I currently have a php snippet that does the following:
 *     ```wp-block-code
       function populateMake() {
       global $wpdb;
   
       // Initialize an empty HTML string for options
       $htmlOptions = '';
   
       // Query for distinct 'make' values from your table
       $query = "SELECT DISTINCT make FROM vehicles";
       $results = $wpdb->get_results($query);
   
       // Build HTML options for the makeDropdown
       foreach ($results as $result) {
         $make = $result->make;
         $htmlOptions .= "<option value=\"$make\">$make</option>";
       }
   
       // Output the HTML options
       return $htmlOptions;
       }
       add_shortcode('populateMake_shortcode', 'populateMake');
       ```
   
 * Then, I am trying to call the shortcode through a Javascript code snippet:
 *     ```wp-block-code
       <script>
   
       document.addEventListener('DOMContentLoaded', function() {
   
       function injectCustomDropdown() {
         const makeDropdown = document.getElementById('makeDropdown');
   
         // Generate the shortcode with the specified content
         const shortcode = '<?php echo do_shortcode("[populateMake_shortcode]");?>';
   
         // Set the HTML of the makeDropdown to the generated shortcode
         document.getElementById('makeDropdown').insertAdjacentHTML('beforeEnd', shortcode);
         //makeDropdown.innerHTML = shortcode;
       }
   
       injectCustomDropdown();
   
       });
   
       </script>
       ```
   
 * Since this is a HTML snippet, I can’t get the php to show. Is there a way around
   this? It reads it as a comment, shows in the console as <!–php ……
 * Thanks in advance!

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/cant-generate-code-snippet-data/#post-17195770)
 * How are you inserting the HTML snippet into your page?
 * If you’re using the shortcode, have you made sure to include the `php=true` argument?

Viewing 1 replies (of 1 total)

The topic ‘Can’t generate code snippet data’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [2 years, 7 months ago](https://wordpress.org/support/topic/cant-generate-code-snippet-data/#post-17195770)
 * Status: resolved