简体   繁体   中英

Database structure, how to think

Im making a football system were I put in all the games a team has played with results, participants for each game and if you have scored, you get an score + 1 in your profile for example.

The structure looking like this right now:

users:
ID - Name - Games - Wins - Losses - Goals - Assist - 2min

event:
ID - opponents - Results - UserID

Participants 
ID - UserID - EventID

And I wondering if this really is the best way, problem that I have found with this is that you can't see who has scored in which game for example since Im only updating the users table with + 1 in Goals. So now Im thinking off something like this:

users:
ID - Name

event:
ID - opponents - Results - UserID

Participants 
ID - UserID - EventID - Games - Wins - Losses - Goals - Assist - 2min

The good think here is that I can see which player has scored in which game, thats really nice to see! But in the userprofile, I have to count all goals from from participants table with the UserID on current user we are viewing, so the questions is, if I have shit loads of posts in participants will it take such a long time to run that query?

Thanks for input.

Update:

Lets say Im using the second option and want to count them.

$query = "SELECT count(assist) as aassist FROM `participants` WHERE `mid`='$q'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
    while($row = $result->fetch_assoc()) {
echo $row['aassist'];

I get a totally wrong number here if count them manually via PHPadmin.

除非您有成千上万的记录,否则只要从“参与者”表中求和就不会有任何性能问题,因此我将采用第二种方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM