PHP包括显示脚本而不是输出

时间:2014-03-08 10:34:06

标签: php mysql php-include

我对PHP很新,但以前能够使用包含文件。

我正在尝试将动态联赛排名表添加到页面中。

代码在页面上可以正常工作,但是当我尝试将其添加到包含文件时,它只显示脚本。我认为这是一个问题,你可以在包含中使用什么,但我很难弄清楚你在包含文件中能做什么或不能做什么的规则是什么?

两个文件都位于同一目录中,我正在使用语法。

我想要包含的代码是:

      $result = mysql_query("
        select team, 
        count(*) played, 
        count(case when HomeScore > AwayScore then 1 end) wins, 
        count(case when AwayScore > HomeScore then 1 end) lost, 
        count(case when HomeScore = AwayScore then 1 end) draws, 
        sum(HomeScore) goalsfor, 
        sum(AwayScore) goalsagainst,
        sum(HomeScore) - sum(AwayScore) goal_diff, 
        sum(case when HomeScore > AwayScore then 3 else 0 end + case 
        when HomeScore = AwayScore then 1 else 0 end) score 
        from (select 
            HomeTeam team, 
            HomeScore, 
            AwayScore 
        from Game 
            union all 
        select  AwayTeam, 
            AwayScore, 
            HomeScore 
        from Game) a 
        group by team 
        order by score desc, 
        goal_diff desc;");

  echo "<table border='1'>
  <tr>
    <th>Team</th>
    <th>Win</th>
    <th>Loss</th>
    <th>Tie</th>
    <th>Goals For</th>
    <th>Goals Against</th>
    <th>Points</th>
  </tr>";

  while($row = mysql_fetch_assoc($result))
    {
      echo "<tr>";
      echo "<td>" . $row['team'] . "</td>";
      echo "<td>" . $row['wins'] . "</td>";
      echo "<td>" . $row['lost'] . "</td>";
      echo "<td>" . $row['draws'] . "</td>";
      echo "<td>" . $row['goalsfor'] . "</td>";
      echo "<td>" . $row['goalsagainst'] . "</td>";
      echo "<td>" . $row['score'] . "</td>";
      echo "</tr>";
    }
  echo "</table>";

格式化的道歉,仍然习惯于间距!

谢谢你们

1 个答案:

答案 0 :(得分:1)

将所有PHP代码包含在标记中。