How can I show random values from a database

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

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

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

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.

3 Likes

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

1 Like

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.

Hang on, so you don’t want to show it randomly? :thinking:

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?

1 Like

Also, what database are you using?

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

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?

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.

MySQL Server

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…

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

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

yes, but only with one row

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

I will try and let you know, thank you