# How can I show random values from a database

**URL:** <https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655>\
**Category:** Ignition\
**Created:** [April 15, 2021, 5:35pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655 "2021-04-15T17:35:03Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![eponce](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eponce](https://forum.inductiveautomation.com/u/eponce)\
**Post date:** [April 15, 2021, 5:35pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/1 "2021-04-15T17:35:03Z")

</div>

I want to show values ​​from a database but in a random way, I have already been searching but I can’t find how to do it because the values ​​are shown to me in table form.  
Thank you for your answers

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 15, 2021, 6:03pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/2 "2021-04-15T18:03:30Z")

</div>

Can you give what your database table is and what sort of random outputs would be acceptable from it?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 15, 2021, 6:07pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/3 "2021-04-15T18:07:00Z")

</div>

As long as you aren’t looking for good randomness you could do this with scripting.

```auto
import random

ds = system.db.runQuery('SELECT * FROM YOURTABLE')
randomRow = random.randint(0,ds.getRowCount())
randomCol = random.randint(0,ds.getColumnCount())

value = ds[randomRow][randomCol]

```

Not sure exactly what you’re trying to accomplish. Almost certainly a better way.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 15, 2021, 6:08pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/4 "2021-04-15T18:08:42Z")

</div>

Beat me to it, although I wasn’t going to be nearly as detailed 😆

---

<div class="post-metadata">

**Author:** ![eponce](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eponce](https://forum.inductiveautomation.com/u/eponce)\
**Post date:** [April 15, 2021, 6:35pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/5 "2021-04-15T18:35:35Z")

</div>

this is my query:  
**select** frec **from** table1 **where** t\_stamp **between** ‘2021-03-26 14:00:00’ **and** ‘2021-03-26 14:06:00’

It shows me the values ​​in that time interval but what I want is that instead of showing it to me in the form of a table, I want to show either a display or a label, show data by data from start to finish.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 15, 2021, 6:44pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/6 "2021-04-15T18:44:08Z")

</div>

Hang on, so you don't want to show it randomly? 🤔

> [@eponce](#):
>
> I want to show values ​​from a database but in a random way

Now would also be a good time to ask Vision or Perspective?

And when you say "data by data", what do you mean? I assume you only want to show a single row at a time. Does the user need to press buttons to advance to the next row? Is it more an automatic marquee of the rows?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 15, 2021, 6:45pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/7 "2021-04-15T18:45:00Z")

</div>

Also, what database are you using?

---

<div class="post-metadata">

**Author:** ![eponce](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eponce](https://forum.inductiveautomation.com/u/eponce)\
**Post date:** [April 15, 2021, 6:48pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/8 "2021-04-15T18:48:15Z")

</div>

what I want is to show the first data of the query, then delete and show the second, and so on.  
thank you

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 15, 2021, 6:49pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/9 "2021-04-15T18:49:41Z")

</div>

> [@eponce](#):
>
> first data of the query, then delete and show the second, and so on.

So you need it to display row by row automatically with a timedelay between showing subsequent rows? What happens when you get to the end?

**Vision or Perspective?**

---

<div class="post-metadata">

**Author:** ![eponce](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eponce](https://forum.inductiveautomation.com/u/eponce)\
**Post date:** [April 15, 2021, 6:52pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/10 "2021-04-15T18:52:23Z")

</div>

at random no, it’s in perspective  
“data by data” I mean that it shows me the first value of the query, then the second and so on without having to press a button to give me the following data.

---

<div class="post-metadata">

**Author:** ![eponce](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eponce](https://forum.inductiveautomation.com/u/eponce)\
**Post date:** [April 15, 2021, 6:53pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/11 "2021-04-15T18:53:09Z")

</div>

MySQL Server

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 15, 2021, 6:57pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/12 "2021-04-15T18:57:02Z")

</div>

I’m not at a pc, but you’ll want to bind the query to a custom prop as json (preferably), then bind your label text prop to a particular index of the json prop. I don’t know how you want to do the marquee timing…

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 15, 2021, 7:03pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/13 "2021-04-15T19:03:14Z")

</div>

You mean the first column of the first, row, then the second column, etc. and then move on to the next row of data?

---

<div class="post-metadata">

**Author:** ![eponce](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eponce](https://forum.inductiveautomation.com/u/eponce)\
**Post date:** [April 15, 2021, 7:05pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/14 "2021-04-15T19:05:13Z")

</div>

I do the query in a named queries and then I link it to a text label

---

<div class="post-metadata">

**Author:** ![eponce](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eponce](https://forum.inductiveautomation.com/u/eponce)\
**Post date:** [April 15, 2021, 7:06pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/15 "2021-04-15T19:06:43Z")

</div>

yes, but only with one row

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 15, 2021, 7:09pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/16 "2021-04-15T19:09:54Z")

</div>

If you bind the query directly to the label’s `text` prop, you can’t manipulate it before displaying it. You need to bind it to an intermediate property first, as I said, and then use that to get the row that you want to display.  
E.g.  
`this.custom.resultset[0].colName`

Where you are binding your query to custom.resultset

---

<div class="post-metadata">

**Author:** ![eponce](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eponce](https://forum.inductiveautomation.com/u/eponce)\
**Post date:** [April 15, 2021, 7:21pm UTC](https://forum.inductiveautomation.com/t/how-can-i-show-random-values-from-a-database/45655/17 "2021-04-15T19:21:02Z")

</div>

I will try and let you know, thank you
