AC
Posts: 0
Joined: Wed Oct 08, 2014 8:53 pm

How can I randomly retrieve image from the database

Dear appery staff I have a question here and hope someone can help me out.

I have N images with descriptions stored in the database. I created some pages with image component in each page. I want to make the page A randomly show one image from the database and next page, page B, randomly show one image from the N-1 images, page C, N-2 images. and so on.

Is there any tutorial I can use for my case ?

Thanks,

AC
Posts: 0
Joined: Wed Oct 08, 2014 8:53 pm

How can I randomly retrieve image from the database

it seems like the old post about using the math.random() is not suitable for this case. I cant put all pictures to the app since I want to add more pictures later so I think using backend database is better than local phone storage, Please help/!

AC
Posts: 0
Joined: Wed Oct 08, 2014 8:53 pm

How can I randomly retrieve image from the database

(update) currently, I use a stupid way...... I put a col in my database named "index" and place numbers there. In the page, I use math.random() to generate a random number and store it to a local variable. I tried to use a query service but it didnt work, I used the code return '{"username":"'+value+'"}'; in my query request mapping.

Please help!

AC
Posts: 0
Joined: Wed Oct 08, 2014 8:53 pm

How can I randomly retrieve image from the database

sorry it is return '{"index":"'+value+'"}';

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How can I randomly retrieve image from the database

Hello,

1) Get all files and save this array into storage variable: https://devcenter.appery.io/documenta...
2) get random file using math.random() by array's index

AC
Posts: 0
Joined: Wed Oct 08, 2014 8:53 pm

How can I randomly retrieve image from the database

Hi Sergiy, I am not sure I know how to get all images to a array and store them into a local storage by reading the link you sent. Can you give me some more deep tips?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

How can I randomly retrieve image from the database

Hello,

You can define your model data structure as an array, and link storage to this model, this is shown in our docs here -- https://devcenter.appery.io/documenta...

Return to “Issues”