带有多个按钮的表 - 需要获取我在php中单击的按钮的值。

时间:2016-07-05 11:11:27

标签: php forms

下表包含带值的按钮。单击按钮时,我想继续" predictSeason.php"。假设我想打印/回应我在那里选择的团队(即点击按钮的价值) - 我该怎么做?

<table class ="teamTable">
    <form action="predictSeason.php" method="post">
      <?php
      $number_per_row = 5;
      $i = 0;
      foreach ($soccerseason->getTeams() as $team) {
          if (($i % $number_per_row) == 0) {
              echo '<tr>';
          }
          ?>
        <td class="crestTd"style="background-image:url(<?php echo $team->crestUrl ?>);">
          <button id="button<?php echo $i ?>" name="button<?php echo $i ?>" class="tableButton" value="<?php echo $team->name ?>"></button>
        </td>
        <?php
        if (($i % $number_per_row) == $number_per_row - 1) {
            echo '</tr>';
        }
          $i = $i + 1;
      }
      ?>
    </form>
  </table>

1 个答案:

答案 0 :(得分:0)

你应该写

    <table class ="teamTable">
    <form action="predictSeason.php" method="post">
      <?php
      $number_per_row = 5;
      $i = 0;
      foreach ($soccerseason->getTeams() as $team) {
          if (($i % $number_per_row) == 0) {
              echo '<tr>';
          }
          ?>
        <td class="crestTd"style="background-image:url(<?php echo $team->crestUrl ?>);">
          <button id="button<?php echo $i ?>" name="button<?php echo $i ?>" class="tableButton" value="<?php echo $team->name ?>" type="submit" ></button>
        </td>
        <?php
        if (($i % $number_per_row) == $number_per_row - 1) {
            echo '</tr>';
        }
          $i = $i + 1;
      }
      ?>
    </form>
  </table>
相关问题