当我想在 HTML 中执行 PHP 函数时,PHP 函数不起作用

标签 php html mysql database

我想在 accueil.php 中包含 functions.php 中的函数,但它不起作用。

查看我的 html 代码:

<div class="milieudepage">
    <table>
        <tr>
          <th> Equipe 1 </th>
          <th> Equipe 2 </th>
          <th> Drapeau 1 </th>
          <th> Drapeau 2 </th>
          <th> Score 1 </th>
          <th> Score 2 </th>
          <th> Buvettes </th>
          <th> Volontaires </th>
        </tr>
        <?php
        include("functions.php");
        AfficheMatch();
        ?>
    </table>
  </div>

functions.php中查看我的php代码:

<?php
include 'connect.php';

function AfficheMatch()
{
  echo "coucou";
  $req = $bdd->prepare("SELECT * FROM Equipe");
  $req->execute();

  while($donnees = $req->fetch())
  {
      echo '<tr><th>'$donnees['pays']'</th><th>'$donnees['drapeau']'</th></tr>';
  }
}
?>

最佳答案

如果看不到代码的其余部分,很难说,但我会尝试一下:

function AfficheMatch()
{
  global $bdd;
  echo "coucou";
  $req = $bdd->prepare("SELECT * FROM Equipe");
  $req->execute();

  while($donnees = $req->fetch())
  {
      echo '<tr><th>'.$donnees['pays'].'</th><th>'.$donnees['drapeau'].'</th></tr>';
  }
}

问题 1:原始代码中存在语法错误,变量正好与字符串相对应,例如 '<code>'$var 。这是行不通的,PHP 要求您使用 . 连接字符串和/或变量。运算符(operator)。所以它会是 '<code>'.$var .

问题2:需要引用全局变量$bddglobal函数内的关键字以便访问它。

关于当我想在 HTML 中执行 PHP 函数时,PHP 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36703631/

相关文章:

javascript - 倒计时不断变化

php - 如果 classmap 实际上更快,为什么要在 composer 中使用 PSR-0 或 PSR-4 自动加载?

JavaScript 确认删除不起作用

html - 如何更改字符的html按钮中的字体

javascript - 以下切换/poptext 不起作用

mysql - MySQL 中选定行的日期

php - 为什么带有 "or"的示例查询不使用索引?

php - 是否有 PHP 函数来解决这个问题?

html - 文本框切断

带有否定和/或多个条件的mysql一对多查询