我如何获得一个if到mysql代码?

I want to program a site, where you can see the results of some soccermatches and where you can see, whether the game is still running.

In the following code i added some comments (//...), so that you can better understand it.

I got this code, for checking, whether we are in a time period:

$time = date("H:i");
if(($time >= "16:00") && ($time <= "18:00"))
{
    echo "live";

}  

This code, i have to put in a cell of a table, but i do not know, how to do.

Sorry for my bad English, I'm German.

Here is the code of my page:

<?php

// First i connect to database
  $connection = new PDO('mysql:host=host;dbname=dbname', 'user',  'password', array(
  PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
  ));

  // I take the date from the database

foreach($connection->query('SELECT * FROM tablename where DATE(datum)=CURDATE() ORDER BY id ASC  LIMIT 1') as $row){


      $datum = $row['datum'];
      $datumm = $row['datumm'];

      echo "  
        <div> 
          <h3>".$datumm."</h3>   
        </div>
      ";
    }
    ?>

// Then I connect again to this database, but now i get the teams who are playing (Heimteam, Gastteam), the starting time (Starzeit) and the final Score (Ergebnis)

<?php

        $connection = new PDO('mysql:host=localhost;dbname=name', 'name',  'pw', array(
  PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
  ));
echo "
<table>
    <thead>
        <tr>
            <th>time</th>
            <th></th>
            <th>home team</th>
            <th></th>
            <th>score</th>
            <th></th>
            <th>other team</th>

        </tr>
    </thead>

    <tbody>
";


foreach($connection->query('SELECT * FROM tablename where DATE(datum)=CURDATE() ORDER BY id ASC ') as $row){



      $starttime= $row['uhr'];
      $endtime= $row['ende'];
      $teamA= $row['heimteam'];
      $teamB= $row['gastteam'];
      $score= $row['ergebnis'];
      $date= $row['datumm'];



      echo "

    <tr>
    <td>".$starttime."</td>
    <td type='hidden'>".$endtime."</td>
    <td>|</td>
    <td align='right'> ".$teamA."</td>
    <td> </td>
    <td align='center'>".$score."</td> //**<--- Here i have to put in the checking of the time period**
    <td> </td>
    <td align='left'>".$teamB."</td>


    </tr>

      ";
 }


 ?>

But when the game is still running, there should not stand the Score, but "live" so that the user can see, that it is running.

I hope you understand me. Please, can someone help me? It would be very nice of you!

Thank you!

foreach($connection->query('SELECT * FROM tablename where DATE(datum)=CURDATE() ORDER BY id ASC ') as $row){



  $starttime= $row['uhr'];
  $endtime= $row['ende'];
  $teamA= $row['heimteam'];
  $teamB= $row['gastteam'];
  $score= $row['ergebnis'];
  $date= $row['datumm'];

// check if match still running or finish
if(match still running){
$status = "LIVE";
}else{
$status = "total score should here";
}

  echo "

<tr>
<td>".$starttime."</td>
<td type='hidden'>".$endtime."</td>
<td>|</td>
<td align='right'> ".$teamA."</td>
<td> </td>
<td align='center'>".$status."</td> //**<--- just put $status because you have already check wheter match still running or finish so the result is LIVE if match still running and show the score if match finish**
<td> </td>
<td align='left'>".$teamB."</td>


</tr>

  ";
}


?>

i hope you can edit my checking pseudo code because your code seems confusing for me.