# Binding for radio group?

**URL:** <https://forum.inductiveautomation.com/t/binding-for-radio-group/55962>\
**Category:** Ignition\
**Created:** [February 10, 2022, 4:40am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962 "2022-02-10T04:40:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [February 10, 2022, 4:40am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/1 "2022-02-10T04:40:01Z")

</div>

I had posted " [Dynamic radio group?](https://forum.inductiveautomation.com/t/dynamic-radio-group/39039)" previously, but want I want to do is bind a radio group to a table in MySQL as shown. It looks like this is not possible, as I get an expression error. Is there a way to dynamically bing a radio group to a database table?

 ![ig_radiobutton_binding_2022-02-09 at 10.33.05 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/6910f738195b33bf556bd42423ef8a84c856c131.jpeg)

![ig_radiobutton_binding_mysql_2022-02-09 at 10.32.09 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/e/ae70849ee8efaac3a041be0c5faecd72c607a636.jpeg)

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [February 10, 2022, 3:43pm UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/2 "2022-02-10T15:43:49Z")

</div>

Hi @pdixon, you will need to use a script transform in the binding and iterate through the dataset to provide the correct structure that the radios array is expecting. If you want to then save this back to the database you will need to use an onChange script or the appropriate event handler for the component to update the database.

If you need any further information, let me know.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [February 10, 2022, 3:51pm UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/3 "2022-02-10T15:51:21Z")

</div>

return format json might be enough, maybe if the query is good constructed xd

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [February 11, 2022, 3:22am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/4 "2022-02-11T03:22:22Z")

</div>

How would I get the size of the array from the MySQL table? I need to look at the number of rows in the table and pass that into the expression. Is there a way to do that?

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [February 11, 2022, 3:52am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/5 "2022-02-11T03:52:34Z")

</div>

I tried this, but it doesn’t work

 ![cvoz_tablesize_2022-02-10 at 9.51.28 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4e55af3ab685acb7fbd56c6f58f5202b5d1f738b.jpeg)

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [February 11, 2022, 4:12am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/6 "2022-02-11T04:12:23Z")

</div>

I figured it out

 ![cvoz_tablesize_2022-02-10 at 10.11.17 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/6/a6f0422b6ab7bea321c42205955ff691d5305ed6.jpeg)

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [February 11, 2022, 4:39am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/7 "2022-02-11T04:39:39Z")

</div>

I finally figured it out

 ![cvoz_dynamicradio_2022-02-10 at 10.38.16 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/9/e9f6659a8748a984b1aaccf17118ee73f17ef4bb.jpeg)

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 11, 2022, 4:45am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/8 "2022-02-11T04:45:33Z")

</div>

Great! But it looks dirty

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [February 11, 2022, 4:54am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/9 "2022-02-11T04:54:45Z")

</div>

I welcome any cleaning recommendations, but I am pressing on since I have it working

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [February 11, 2022, 10:00am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/10 "2022-02-11T10:00:39Z")

</div>

> [@pdixon](#):
>
> ![ig_radiobutton_binding_2022-02-09 at 10.33.05 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/6910f738195b33bf556bd42423ef8a84c856c131.jpeg)
> 
> ig\_radiobutton\_binding\_2022-02-09 at 10.33.05 PM2608×1962 309 KB

have you tried pressing this  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/c/9cb241c9f836fd2f55c0166c137f526370c2c422.png)

and set it to json format?

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 11, 2022, 3:57pm UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/11 "2022-02-11T15:57:18Z")

</div>

I would start by changing binding type from expression to named query, avoiding that weird reference to the DB table name. That only have sense if the table name is dynamic.  
Ones you have data from the query you can do the transform if needed.

To get the length of rows, avoid creating another query using `COUNT(*)`, just use `len()` or `.rowCount`, depending on the return format.

You loop looks ok.

And last, you have two `return` in the same indent, that has no sense. I don’t know how that is even working.

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [March 8, 2022, 2:57am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/12 "2022-03-08T02:57:31Z")

</div>

I cleaned it up by recognizing that the fields were not being mapped because I was not returning them with the right names for the radio button. Now I have a query that returns the right names for a clean implementation.

Thanks for everyone’s help.

 ![Screen Shot 2022-03-07 at 8.55.33 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/4/f49f6316131b964e7b0421852ca4536847d73ef6.jpeg)

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [March 8, 2022, 4:13am UTC](https://forum.inductiveautomation.com/t/binding-for-radio-group/55962/13 "2022-03-08T04:13:21Z")

</div>

Looks better
