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.

PHP Forum


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



Freelance Jobs

Reply
Adding results from various tables
Old 11-18-2008, 12:36 AM Adding results from various tables
Novice Talker

Posts: 7
Name: Lyndon
Trades: 0
Hello All,

I have created a website that covers a horse racing syndicate and at present I have a table for each of the horses that details each race they run in (i.e. date, distance, placing, money won etc etc)

Obviously from those tables I can retrieve stats on individual horses for example total money won, number of wins, number of seconds etc.

How would I combine the results to show the same data but as a whole syndicate? In other words total wins, total money by all the horses combined.


Any help appreciated
__________________
Lyndon
maceotago is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-18-2008, 03:20 AM Re: Adding results from various tables
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
at present I have a table for each of the horses that details each race they run in
That's a very poor way of using a database.

To do what you need easily and efficiently, you would really need to restructure the datastore otherwise you are will have to retrieve each set of data with a seperate call to the database and do the calculations in server side code.
__________________
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-18-2008, 03:39 AM Re: Adding results from various tables
Novice Talker

Posts: 7
Name: Lyndon
Trades: 0
Quote:
Originally Posted by chrishirst View Post
That's a very poor way of using a database.

To do what you need easily and efficiently, you would really need to restructure the datastore otherwise you are will have to retrieve each set of data with a seperate call to the database and do the calculations in server side code.

Ok thanks.

What structure would you recommend? I am relatively new to PHP so I have just really been self taught!
__________________
Lyndon
maceotago is offline
Reply With Quote
View Public Profile
 
Old 11-18-2008, 04:13 AM Re: Adding results from various tables
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Can't be specific but offhand;

tables
horse: all the horse detail needed
owner: just the owners details
track: id, name, location etc
race: id, date, distance, track.id, name etc

results: horse.id, race.id, position, time, etc

horse to owner link: owner.id, horse.id
horse to race link: horse.id, race.id, position, prizemoney

then to get any collection of data it just needs JOIN queries to pull the required info out.

These are just approximations of course, to define an exact database schema needs all the information you expect to store.
__________________
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-18-2008, 07:05 AM Re: Adding results from various tables
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
In addition, i would suggest reading up on Database Normalization and general database design, would be useful to make things easier for yourself in the long run.
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 11-18-2008, 03:27 PM Re: Adding results from various tables
Novice Talker

Posts: 7
Name: Lyndon
Trades: 0
Great! Thanks for your help guys!
__________________
Lyndon
maceotago is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Adding results from various tables
 

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.37378 seconds with 12 queries