Forum BigDB Load database objects from index in pages

Discussion and help relating to the PlayerIO database solution, BigDB.

Load database objects from index in pages

Postby flexcool354 » April 1st, 2011, 8:58 pm

In my game i have some sort of market where you can buy products by other players. The products are stored in a database object and loaded using different indexes, like load by price, by amount...

But how do i load it in pages?

Something like loading the first 20 database objects on page one in my game
then when i am on page 2 i load the 20 next database objects
Instead of loading all of them at once?

And also could you add an expire date for databaseobjects, so if I have a product, i can make it get deleted after 30 days. Unless the user owning the product renews it, which should move the expiration date
flexcool354
 
Posts: 35
Joined: September 26th, 2010, 5:31 pm

Re: Load database objects from index in pages

Postby Henrik » April 1st, 2011, 9:11 pm

First 20: LoadRange("table", "index", null, null, null, 21), skip displaying last object. If you get 21 objects back, you can display a button to load the next page. If not, you're at the end of the index.

Next 20: LoadRange("table", "index", null, [21st object's value], null, 21), skip displaying object, etc.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Load database objects from index in pages

Postby flexcool354 » April 1st, 2011, 9:13 pm

I can make a next page and previous page button this way, but what if my user wants to go to page ### do i then have to send him through all the pages?
flexcool354
 
Posts: 35
Joined: September 26th, 2010, 5:31 pm

Re: Load database objects from index in pages

Postby Henrik » April 1st, 2011, 9:23 pm

Going to a specific page without context requires something similar to the LIMIT statement in SQL, and it's not something BigDB supports. Sorry about that.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Load database objects from index in pages

Postby jasonMcIntosh » April 1st, 2011, 10:00 pm

I am probably completely wrong and entirely confused, but if you know that each of your pages is 20 items, couldn't you compute the "page number" and load just the 20 items from that page for the user?

Like if you want page 5, you know that 20 * 5 = 100, so you load from index 100-120?
Jason McIntosh
Otherwhere Gameworks
jasonMcIntosh
 
Posts: 81
Joined: February 25th, 2011, 4:51 am

Re: Load database objects from index in pages

Postby flexcool354 » April 4th, 2011, 9:12 pm

I've tried doing as you said, but i then came into a problem. Many of my databaseobjects have the same value. So when i load the 21 with the highest value, and attempt to load the next, it will still give me the first objects because they all have the same value.

I'd really like a better way to load objects using indexes because i don't want to load all at once since that would be a big waste of bandwidth.
flexcool354
 
Posts: 35
Joined: September 26th, 2010, 5:31 pm

Re: Load database objects from index in pages

Postby flexcool354 » April 6th, 2011, 8:29 pm

Wait you gave me an idea, i can have a copy with some of the information on a separate mysql server
when the person wants to load a page, i'll tell the other server to get the item names, flash will then download them and display the objects.

Not as fast, but it'll allow me to use all of the sql things
flexcool354
 
Posts: 35
Joined: September 26th, 2010, 5:31 pm

Re: Load database objects from index in pages

Postby cjcenizal » April 7th, 2011, 4:55 am

Hey flexcool, could you update us with how that works out for you? I'm really interested in how you solve that problem. It sounds like you're on the right track.
cjcenizal
Paid Member
 
Posts: 115
Joined: March 29th, 2011, 12:31 am

Re: Load database objects from index in pages

Postby flexcool354 » April 7th, 2011, 5:10 pm

Sure, what i have done now is that i made some php gateway that connects to a mysql server.
So when a user does something the serverside code automaticly goes to the website and updates the database
http://flexweb.site90.com/updateWorkplace.php (you need a secret pass key to prevent users from doing stuff they aren't supposed to)

To list the item i go to a different page. In this case:
http://flexweb.site90.com/ListBySalary. ... rmat=false
change the post parameters to modify the output. Sorry if there aren't any objects yet If i upload to quickly the mysql server won't work.

EDIT: I just realised that my site is very vulnerable for a sql injection
Last edited by flexcool354 on April 7th, 2011, 5:51 pm, edited 2 times in total.
flexcool354
 
Posts: 35
Joined: September 26th, 2010, 5:31 pm

Re: Load database objects from index in pages

Postby cjcenizal » April 7th, 2011, 5:21 pm

Cool, thanks! Looks like an elegant solution!
cjcenizal
Paid Member
 
Posts: 115
Joined: March 29th, 2011, 12:31 am


Return to BigDB



cron