Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Picking some random rows once a day
Old 11-24-2011, 04:36 PM Picking some random rows once a day
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I'm creating a text-based browser game, as a "hobby project", and have come to a small issue I'd like some help with.

One of the actions a player will be able to do is to go on missions. I have a table containing different kinds of missions, and as of right now I pick a few of them at random and display them every time the page loads.

However, I want the ones I pick to be remembered (individualy, for each user). Meaning that those few missions are the only ones which that player can go on that day, and new random missions aren't picked until the next day.

So far I havn't been able to come up with a smart db design for this, and would appreaciate some suggestions.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
 
Register now for full access!
Old 11-24-2011, 06:21 PM Re: Picking some random rows once a day
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
I what database server model?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-24-2011, 06:59 PM Re: Picking some random rows once a day
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Come again?
Perhaps I should have mentioned, I'm likely not as experienced as many people here when it comes to databases. I really don't know what you mean by a "database server model". I'm guessing you're not simply asking what DBM I'm using, but it's MySQL.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-25-2011, 07:54 AM Re: Picking some random rows once a day
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
depends on what you term as a DBM? To me dBm refers to a signal power ratio.
But in this context I'll assume database manager which would refer to a tool for the management of a database server. Such as phpMyAdmin for MySQL

The database server model would refer to what kind of server it is ie: Oracle, Access, MySQL, PostGre etc.

Most people who are not aufait with database systems seem to believe that MySQL is a language rather than being a server "family"

anyway:

if the table is relatively small (10,000 rows or less)
Code:
select fieldlist from table order by rand() limit n;
should work successfully. set the value for limit to suit your use.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-25-2011, 12:25 PM Re: Picking some random rows once a day
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Yes, by DBM I meant DataBase Manager :P

According to what I've been tought, a "database" is simply a set of data which in some way refer to each other. It could as well be i.e. a bunch of papers in an old archive. Whereas a DBM is a tool/system which handles (or manages) a database, i.e. MySQL or Oracle.

In those terms, I guess phpMyAdmin would be an... interface(?) or tool which uses a DBM (MySQL in this case).


Anyway, lets return to my problem
I already have a way of selecting the missions randomly (although I did not use rand()). The problem I'm having is to remember those missions, perhaps by storing their IDs in another table or something. I havn't come up with a smart way, well any way actually, to do that.

Let me give an example scenario.
The first time a player opens the mission page, i pick lets say 3 random missions to display. If the player goes to another page, and then returns, he will still see the same 3 missions. Now lets say he does one of the missions, which takes some time, and then comes back to the mission page. Now there are only 2 missions left for him to do. If he does those aswell and then comes back to the mission page, it will just state that there are no more missions right now. The player will not get new missions until the next day, when 3 new missions will be randomly picked.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 11-25-2011 at 12:26 PM..
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-25-2011, 04:46 PM Re: Picking some random rows once a day
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A database is simply a collection of data items which may or may not have any relationship to each other at all. The only commonality is the structure of the records held within it.
A database could be a simple as a "flat file" (eg: a XML file) or as complex as an "inverted index" data structure.

Oracle and MySQL are database servers. Systems that can hold many different unconnected database structures.

The only "management" available is the built in command language.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-25-2011, 04:52 PM Re: Picking some random rows once a day
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Nope, phpMyAdmin IS a database manager.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-25-2011, 04:57 PM Re: Picking some random rows once a day
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
perhaps by storing their IDs in another table or something.
simplest would be a "missionsCompleted table".

Three columns of userID, MissionID, completed. then it is a simple lookup to determine what each user has done.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-25-2011, 07:48 PM Re: Picking some random rows once a day
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Quote:
Originally Posted by chrishirst View Post
simplest would be a "missionsCompleted table".

Three columns of userID, MissionID, completed. then it is a simple lookup to determine what each user has done.
Ha! Well, that was easy
I can't see why I couldn't think of such a simple idea on my own.
I did just what you wrote, and just added a date field for keeping track of when the missions "expire" and new ones should be picked, and it works like a charm.

Thanks!

And thanks also for clearing up the database and DBM concepts. The course I followed was partly targeted at people who were completely new to databases, so it's quite likely that some things were simplified.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-26-2011, 08:28 AM Re: Picking some random rows once a day
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I can't see why I couldn't think of such a simple idea on my own.
As a programmer you will have a certain mindset for the logical progression of program flow and structure, unfortunately that mindset is pretty much at odds with the mindset needed for structuring database schemas, where you need to be able to visualise the whole thing.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Picking some random rows once a day
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30890 seconds with 12 queries