Page 1 of 1

How can I randomly retrieve image from the database

Posted: Mon May 11, 2015 8:36 pm
by AC

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,


How can I randomly retrieve image from the database

Posted: Tue May 12, 2015 3:22 am
by AC

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/!


How can I randomly retrieve image from the database

Posted: Tue May 12, 2015 4:06 am
by AC

(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!


How can I randomly retrieve image from the database

Posted: Tue May 12, 2015 4:07 am
by AC

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


How can I randomly retrieve image from the database

Posted: Tue May 12, 2015 6:17 am
by Serhii Kulibaba

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


How can I randomly retrieve image from the database

Posted: Tue May 12, 2015 2:56 pm
by AC

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?


How can I randomly retrieve image from the database

Posted: Tue May 12, 2015 7:22 pm
by Illya Stepanov

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...