View Full Version : Automatically Updating Database?
Sugar Rush 07-25-2004, 03:13 AM Alrighty, I wanted to know if there's anyway to get your database to update automatically based on information that's there? How do I explain? Ok, well, the database is for a horse game. And every time a "horse" gets a certain number of "points" the horse gets a new title. Instead of having to manually update title, is there a way to get the title to change when a new number of points is put in the database (i.e. 100 points -> title to Champion, 300 points -> title to Grand Champion)?
I'm working on it with another person, and they know more about the DB than me, so baby steps are helpful :rolleyes:.
Iwishihad 07-25-2004, 03:50 AM Hmmm I did things like this before. What you need to do it ^^^ the points and ALSO check the points against titles they need to get. If over 100, title = this. Get it? :)
Sugar Rush 07-25-2004, 04:18 AM Mmmk. So I have to check the points against the title? I'm sorry, I'm a real beginner at MySQL.
Iwishihad 07-25-2004, 01:17 PM Yup. When you accept someone's points, make a change to the points and if needed, also to the title.
Sugar Rush 07-25-2004, 04:03 PM Thank you so much! I'll try it out sometime today and let you know what happens :). Thank you again!!!
Dude128 07-25-2004, 07:23 PM if you think you'll want to change the titles, you may want to have a second table with the titles and how many points are required to have it.
so you would have a horse table:
horse | points
---
horse1 | 37
horse2 | 12
horse3 | 2
and a table with the titles:
title | points
---
title1 | 1
title2 | 10
title3 | 20
title4 | 30
title5 | 40
etc.
when you get the information on a specific horse from the database, you'll see the number of points: say it's for horse 2, so it will be 12
now get all the different titles from the other table, and compare the number of points the horse has to the number required to get each title: it would stop at title2, because 12 is above the threshold of 10 to get it, but less than the one for title3
does that make sense?
Iwishihad 07-26-2004, 02:48 PM heh that was what I was attempting to say. :froggie2:
Just as a heads up, to the horses table, you might want to add a title section so you don't always have to call up another table for that information and go through the process each time you want to see what title your horse has. Hmm.... did that sound confuzzling or was it just me? :rolleyes:
Sugar Rush 07-29-2004, 06:40 PM Ok, I'm reallyyyy bad at this (lol), so let me see if I got this right.
If I have a second table, when I go into the database and modify a record so that the horse has 30 points, the title for that horse will automatically change from title2 to title3. Right?
Hate to be a bother, but what is the actual coding for that? Or do you know a tutorial site where I can find it? Thank you, thank you, thank you so much!
Iwishihad 07-30-2004, 12:47 PM Well, what you need to do is make a form where you change the points for that certain horse. Then carry that information to another page when hitting submit, and on that page you need to access the the first table, open it, change the point value of a certain horse. Then, (I really don't think you need another table) just use a switch function and or even an if statement
" if (point value is >= 30)
i="Champion" "
i would have to be a string. Very simple. Then when you finish all of your if statements, change the title to the value i should be.
I know that might take a little space and time, but for you, it would be the easiest way to understand. :)
Dude128 07-30-2004, 04:37 PM what I was thinking of was not actually updating the title, just the number of posts. when you get the number of posts, you can then compare it to the titles available, stored in the other table. that way, if you ever wanted to change the possible titles, it would be easier because they aren't stored for every single horse, but rather assigned to the horse when you get the number of posts and compare it to the other table.
but if you don't plan to change them or anything, you can just do it that way. it's really just personal preference :)
Iwishihad 07-31-2004, 12:53 AM Hmmmm but then wouldn't whenever you wanted to display a list of horses and their titles, you would have to check each with the table which would take some times? Excuse the run-on sentance.
|