Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-19-2005, 04:53 PM   #1
Resident Slacker
 
homer15's Avatar
 
Join Date: Dec 2001
Location: Suisun City, California (i know, where the hell is that?!?!?)
Posts: 2,620
sql/php help

hey everyone,

i have an sql table that is laid out as follows:

|ID|Team|Date|Score|

in the ID column, only 2 are going to have the same ID. the ID stands for the game played.

i need to build a page that'd display this properly. for every team, i want to select the game id, appropriate teams and display the date and the scores (preforable, the higher score on top).

here is an example of what i'm talking about.

thanks for any help you can give.
__________________
Friends help you move. REAL friends help you move bodies. - me
quite possibly the best book ever written... by me
homer15 is offline   Reply With Quote
Old 04-19-2005, 10:11 PM   #2
Staff
Premium Member
 
mairving's Avatar
 
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
Two tables should be the answer.

Table 1 ***teams***
id int(11) auto_increment primary key,
name varchar(50),
nickname varchar(50),
description text

Table 2 ***games***
id int(11) auto_increment primary key,
winner_id int(11),
loser_id int(11),
score varchar(5),
game_date date

So with some data in it, it would look like so
***teams***
id | name | nickname | description
1 | New York | Mets | Losers
2 | St Louis | Cardinals | Winners

***games***
id | winner_id | loser_id | score | game_date
1 | 2 | 1 | 10-1 | 20050418
__________________

Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row

Last edited by mairving; 04-19-2005 at 10:14 PM.
mairving is offline   Reply With Quote
Old 04-19-2005, 10:17 PM   #3
Staff
Premium Member
 
mairving's Avatar
 
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
Now if you wanted to do anything like calculate total runs scored and such, you would need to probably make something like
winner_score and loser_score, instead of just the score field.

You also don't need to separate out the nickname but it could be handy.
mairving is offline   Reply With Quote
Old 04-19-2005, 10:53 PM   #4
Resident Slacker
 
homer15's Avatar
 
Join Date: Dec 2001
Location: Suisun City, California (i know, where the hell is that?!?!?)
Posts: 2,620
thanks mairving. do you have any idea how i could get this into the table format i want using php?
homer15 is offline   Reply With Quote
Old 04-20-2005, 08:20 AM   #5
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668


Assuming you make the winner and loser score like mairving was talking about, your SQL would look like this:

Games won:
SELECT w.name, l.name, g.winner_score, g.loser_score, g.date
FROM games g
INNER JOIN teams w ON g.winner_id=t.id
INNER JOIN teams l ON g.loser_id=t.id
WHERE w.name='team name'
ORDER BY g.date

Games lost:
SELECT w.name, l.name, g.winner_score, g.loser_score, g.date
FROM games g
INNER JOIN teams w ON g.winner_id=t.id
INNER JOIN teams l ON g.loser_id=t.id
WHERE l.name='team name'
ORDER BY g.date

This will pull all of a team's results (in two record sets) ordered by date. From here you can dynamically build your tables using php's built in SQL functions.

Last edited by faulkner132; 04-20-2005 at 10:30 AM.
faulkner132 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:21 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2