Help - Search - Members - Calendar
Full Version: Better to insert or query stats?
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
Tyler2499
I am building an application and I was curious if I am better off querying results or inserting them into the database. What I mean is I have a racing league and I want to track stats (wins, races, dnfs...). So for example, am I better off inserting a win into a stats table or querying the win from the race results? I am anticipating a lot of race results so I was wondering the best/fastest way to get around this.
Any help is appreciated, thanks.
rc69
Well at some point in time, the database will have to be updated with the new race results right? So that means you're going to be forced to do an update/insert into at some point.
If you could give a more detailed pseudo-algorithm of what you're thinking, i could probably advise you on which would be the better route to go.
Tyler2499
I am terrible at coding. I'm just an amateur so you can laugh. Currently I have a beta version that is incomplete. But I found 1024 cms and I do like the way it runs. So now I may be back track just to configure it with the user system. Whole process:
  • Add a Class
  • Add a season
  • Assign Drivers to a season
  • Add Race Results
The way I have it set currently will grab users from the users databse and assign their ID to the season roster. So i was thinking either adding the stats fields to the users table or make a "record book" database and run the stats through there or maybe just query the results.

How its set now is each position has its own insert seeing as though each position has unqiue fields (ex. pos1, racer1, pos2, racer2).

P.s. - If you have read any helpful php/mysql books please post them. I need to learn how to use classes/functions.
derek.sullivan
better than buying books, read about php and mysql at places like pixel2life.com or w3schools..... or you can go to the main php website at php.net and or mysql.com.. don't waste your money on books when you can learn everything you need online for free. also, when you code as a beginner, comment your codes you so know what your code is saying for example:

CODE
<?php

$i = 1; //the variable $i is defined as the number 1

if ($i == 1) { // checks the the varible $i is equal to 1

echo 'yes it matches!'; // displays our result message

}else{ // uh oh!

echo 'no it does not match!'; // displays our result message if it does not match

} // closes and ends our code check

?>


that away, you'll know what you're doing, remember what you did, and can improve your code in the near future. Hope this helps somewhat, sorry I can't further help you with your code.
Tyler2499
I don't know terms for everything but when it comes to applying the code I can do beginner stuff. I just don't know how to save myself time when it comes to repeated tasks. I haven't quite got into classes and all that. Not really why I'm here but thanks for the info. Just trying to find out which is the most efficient way.
rc69
For finite information, like strictly win/loss/dnf info, then i would recommend adding `win`, `loss`, and `dnf` fields to the racer's record (i.e. in the `racers` table, just add the three columns and increment them).

However, if you want more dynamic information, then i think it would be best to record the results of each race in a separate table, and then join that table to the `racers` table. That way you can generate more informative statistics (i.e. which race they won/lost/dnf'd).
Tyler2499
Well, thanks for the information. I believe that storing the stats in it's own table is better because then if I would like to I could have a leaderboard system showing the all time wins and such. Thanks for your help/opinion.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.