Jump to content

Reading from 2 Tables in MySQL Database


jedney

Recommended Posts

Hello.

 

I am trying to do some PHP scripting, to include information from 2 different tables, and I see in my PHP book how to do it, but I do not understand a few things.  So, I will explain everything.

 

I am making a web site for an online gaming team.  This site includes a page called matches.php.  This page includes date, time, match format, match type, map played on, opponent, score, results and a write up on the match. Various elements of the page will be clickable for details (date will be clickable to show details of the match, match format will be clickable for a list of matches in that format only, etc).  One thing I want clickable in this page is the opponent.  The opponent information is kept in a different table.  My plan was, when I create the page in the admin section of the site, to enter a new match, it would give a list for opponents, and read the opponent names from the opponents table, and just echo the name and input it into the matches table under opponent.  But, what I click the opponent name, I want it to show the details of the opponent, but also, the matches that the team had with them.  How I was going to do this was like this:

 

<?php 
SELECT matches.name, opponents.name
FROM opponent, matches
WHERE matches.name = opponent.name
?>

 

To my knowledge, this will link the name row, in both tables.

 

What I can't find, is when I link the opponent name, to show the details, it would be in a isset script to show something allong the lines of matches?opp=1 where 1 would equal the opponent's ID in the table.  How can I pull the opponents ID from the opponents table, while still displaying information from the matches table.  I'm getting lost.

 

Jon

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.