PHP(SQL)选择名称,其中id =更多值

I have table match (which contains "id, date, team1_id, team2_id")

and table team (which contains "id, name")

I need PHP or SQL code that will show name of team(from table team) WHERE "team1_id" and team2_id" = team.id

...actually I have something like this:

$deleteMatch = Database::query('SELECT match.id, match.team1_id, match.date, 
       team.id, team.name FROM `match`, `team` WHERE team.id = match.team1_id');
foreach($deleteMatch as $matchinfo)
{
    ?><option value="<?php echo $matchinfo["id"];?>">
    <?php echo $matchinfo["date"]; echo $matchinfo["name"];?></option>
    <?php
}           

but I need add team2.id(name) to the foreach. ( DATE | TEAM1 NAME | TEAM2 NAME )

Hope you understood me. Thanks for help.

Use this Query:

SELECT match.id, match.team1_id, match.date, 
  t1.id as team1ID, t1.name as team1Name, 
   match.team2_id,t2.id as team2ID, t2.name as team2Name 
 FROM `match` JOIN `team` t1 ON t1.id = match.team1_id 
  JOIN `team` t2 ON t2.id = match.team2_id

SQLFiddle.

$deleteMatch = Database::query('SELECT `match`.id, `match`.team1_id, `match`.date, `team`.id, `team`.name FROM `match` JOIN `team` ON `team`.id = `match`.team1_id' LEFT JOIN `team` ON `team`.id = `match`.team2_id);
foreach($deleteMatch as $matchinfo)
{
?><option value="<?php echo $matchinfo["id"];?>"><?php echo $matchinfo["date"]; echo $matchinfo["name"];?></option>
<?php
 }   

I would do this with 2 inner-join on the team table:

$query = "SELECT match.*, team.* FROM match
          INNER JOIN team ON match.team1_id = team.id
          INNER JOIN team ON match.team2_id = team.id;"

The table should look something like this:

match.id | match.date | team1_team.name | team2_team.name

You can try this SQL query:

SELECT match.id, date, t1.name AS team1, t2.name AS team2
FROM match, team AS t1, team AS t2
WHERE team1_id=t1.id AND team2_id=t2.id

The trick is you need to match every team id to its name separately, so you have to include team table twice. In order to distinguish between both tables, you can use aliases with the help of the AS keyword (in the example, I aliased tables as t1 and t2, respectively)

The resulting table will have 4 columns: id (the match id), date, team1 (the name of team 1) and team2 (the name of team 2), so you can use $matchinfo["team1"] and $matchinfo["team2"] in your php code.