Title: SQL Query with jQuery variable
Last modified: July 9, 2021

---

# SQL Query with jQuery variable

 *  [gercamjr](https://wordpress.org/support/users/gercamjr/)
 * (@gercamjr)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/sql-query-with-jquery-variable/)
 * I am trying to create a snippet that will iterate over a group of radio buttons
   and change their background color based on sql query results. I am trying to 
   make a jQuery script with the .each() function to do the iteration and pass the
   element’s value to the SQl query. But I am not sure how to do that. This is what
   I basically want to do:
 *     ```
       <script>
       	var $j = jQuery.noConflict();
       	var $timeSlot = "";
       	/* write your JavaScript code here */
         	$j( "radio.el-radio-button__orig-radio" ).each(function( i ) {
       		$timeSlot = this.val();
       		queryResults = /*sql query with timeSlot value passed*/
                       /* if queryResults == 1 then this.css-background = "blue" else if queryResults == 2 then this.css-background = "green" else if this.css-background == 3 then this.background == "red" /*
         	});
   
       </script>
       ```
   
    -  This topic was modified 4 years, 10 months ago by [gercamjr](https://wordpress.org/support/users/gercamjr/).
      Reason: forgot to add the $j

The topic ‘SQL Query with jQuery variable’ 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/)

## Tags

 * [code snippet](https://wordpress.org/support/topic-tag/code-snippet/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * 0 replies
 * 1 participant
 * Last reply from: [gercamjr](https://wordpress.org/support/users/gercamjr/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/sql-query-with-jquery-variable/)
 * Status: not a support question