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
linking two MySql tables together
Old 06-23-2005, 08:46 AM linking two MySql tables together
Experienced Talker

Posts: 35
Trades: 0
Hi Guys,

Wondering if anyone can help

I have two tables a 'game' and 'appearances' table saved in mysql database.

Now I want to create a php template to call the data out of these two tables and display the data saved onto my template. Each of these tables hold several record id's

Now I need to somehow link both tables together so that my template sees the 'game' table for the match, and also the 'appearance' table and pulls that out that correct apperance data for that match also. So I think I need to create some sort of unique identifier for each table that pulls the data together?

Here are the two tables:

From the 'game' table

- $matchdate
- $hometeam
- $score
- $awayteam
- $homeone
- $hometwo
- $homethree
- $awayone
- $awaytwo
- $awaythree
- $attendance
- $venue
- $byline
- $competition
- $opening
- $body

From the 'appearances' table

- $shirtone
- $r1
- $shirttwo
- $r2
- $shirtthree
- $r3
- $shirtfour
- $r4
- $shirtfive
- $r5
- $shirtsix
- $r6
- $shirtseven
- $r7
- $shirteight
- $r8
- $shirtnine
- $r9
- $shirtten
- $r10
- $shirteleven
- $r11
- $shirttwelve
- $r12
- $shirtfourteen
- $r14
- $shirtfifteen
- $r15
- $shirtsixteen
- $r16
- $shirtseventeen
- $r17

Now in English those two tables the 'game' table holds all the scores, date of the match, who wrote the report, match report text etc.

The apperances table holds all of the details for each match who played in what game so $shirtone would be the goalkeeper and - $r1 would be who replaced him as sub.

So on my template I may want it to pull out the following data and this is how it would look live:

---------------------
TEMPLATE:

Beaconsfield 3-1 An Other

Goalkeeper: Alan Rush
Replacement: John Walsh
---------------------

So the php for this template would be:

---------------------
TEMPLATE:

<?php echo $hometeam; ?><?php echo $score; ?><?php echo $awayteam; ?>

Goalkeeper:<?php echo $shirtone; ?>
Replacement:<?php echo $r1; ?>
---------------------

But the data is taken from both the tables in the template above, so I want to link them together for each football match played.

Anyone advise?

Ta

Chris
chrisb is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-23-2005, 08:53 AM
Rufo's Avatar
Extreme Talker

Posts: 173
Trades: 0
Set up a column in each table to store a unique id, then use the following SQL to join them:
Code:
SELECT * FROM `game` LEFT JOIN `appearances` ON game.id = appearances.id
Use the normal while() technique to get each row in turn.

Rufo
__________________

Please login or register to view this content. Registration is FREE
Rufo is offline
Reply With Quote
View Public Profile Visit Rufo's homepage!
 
Old 06-23-2005, 09:25 AM
Uche's Avatar
Extreme Talker

Posts: 174
Location: Nigeria/Lagos
Trades: 0
Rufo said it all
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life.

Please login or register to view this content. Registration is FREE
Uche is offline
Reply With Quote
View Public Profile Visit Uche's homepage!
 
Old 06-23-2005, 10:10 AM
Experienced Talker

Posts: 35
Trades: 0
Thanks guys.

Forget what I posted now - sorted!

Last edited by chrisb; 06-23-2005 at 10:19 AM..
chrisb is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to linking two MySql tables together
 

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