Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTimo Bontenbal
9,582 PointsPHP Database structure.
Hi,
I need to build a quite simple php site. The site needs this kind of functionality.
Admin area: add Teams(only the name) and points for teams. Each team can get multiple points. Example: Team1 -> Points 4/10, 7/10 Total score 11/20.
Regular view: If you visit the site people can see how many points each team has gotten.
My question: What kind of database structure should i build? On the admin area an admin can choose a team and then add points to it. Points will be added every week and the site visitors need to see them.
How do you recommend me to start building this? I know this is quite simple. but i cant wrap my head around the database structure.
I am using PHP MyAdmin
Code examples are also welcome :)
Timo Bontenbal
9,582 PointsSimon Woodard The old entries need also to been seen
Chris Malcolm
2,909 Pointsif your asking about the columns and tables would probably do:
team
table
id
, name
-string, timestamp
-timestamp
points
table
id
, points
, user_id
-relation, team_id
-relation
user
table
id
, name
-string ,password
-encrypted string, email
-string, admin
-bool, timestamp
Timo Bontenbal
9,582 PointsChris Malcolm I was researching today a little of relational tables. But i did not find a clear answer on how they work.
Chris Malcolm
2,909 Pointsin essence your relation is just the id of user or team and so you have a means of grabbing the team or user in your sql query. You can also join table data together, using JOIN http://www.w3schools.com/sql/sql_join.asp
Timo Bontenbal
9,582 PointsChris Malcolm Does the id need to be a primary A.I integer?
Chris Malcolm
2,909 Pointshi timo, yes id should be that.
2 Answers
Timo Bontenbal
9,582 PointsComment fail
Simon Woodard
6,545 PointsYou could get away with 2 simple table's in that case. One that lists all the team name with these columns (id - unique identifyer) (team - name of the team)
and then a second table that list all the scores (id - unique identifyer) (team_id - the team this entry corresponds to) (score - the score for this entry) (timestamp - the date of entry)
With this two table database you can call any score based on the date and go back as far as you want, and with unique id's you can display multiple scores for that day and then the total of them as well.
Timo Bontenbal
9,582 PointsSimon Woodard Are those relational tables hard? How would i set records to them?
Simon Woodard
6,545 PointsNope they're not hard at all, when you enter a score into the table you would simply use the id of the team as the relationship, since this would be the common denominator in both tables.
Simon Woodard
6,545 PointsSimon Woodard
6,545 PointsDo you want old database entries to be kept? or do you only want the latest scores listed in the database?