dongliao1948 2015-01-18 15:57
浏览 289
已采纳

我如何获得一个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!

  • 写回答

1条回答 默认 最新

  • dq1230123 2015-01-18 17:00
    关注
    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题