如何将 if 放入 mysql 代码中?

How can i get an if into a mysql code?

我想编写一个网站,在那里你可以看到一些足球比赛的结果,你可以在哪里看到比赛是否还在运行。

在下面的代码中我添加了一些注释(//...),以便您更好地理解它。

我得到了这段代码,用于检查我们是否在一个时间段内:

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

}  

这个代码,我要放到一个table的单元格里,但是我不知道,怎么办。

抱歉我的英语不好,我是德国人。

这是我页面的代码:

<?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>
      ";
    }
    ?>

// 然后我再次连接到这个数据库,但现在我得到了正在比赛的球队(Heimteam、Gastteam)、开始时间(Starzeit)和最终比分(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>

      ";
 }


 ?>

但是当游戏还是运行的时候,不应该出现Score,而是"live"让用户看到,那就是运行.

希望你能理解我。拜托,有人可以帮助我吗?你真好!

谢谢!

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>

  ";
}


?>

我希望你能编辑我的检查伪代码,因为你的代码让我感到困惑。