如何获取由foreach生成的html表的索引/数据


How to get index/data of html table generated by foreach

我加载一个xml文件并循环生成一个html表。在表格的每一行上,我有两个图标更新和删除。当我单击icone删除(例如)时,我想获取行的索引或行的任何信息,以便处理删除xml文件中的节点。我通过将参数传递给 php 函数来尝试使用回显$number,但 GET 在 php 文件中为空。

你知道我怎样才能得到它吗?提前谢谢。

       <table>
        <?php
        foreach($participants as $participant)
        {
        $number = $participant->number;
        $name = $participant->name;
        $note = $participant->note;
        $sexe = $participant->sexe;
        $group = $participant->group;
        $adjust = $participant->adjust;
        ?>
        <tr>
            <td align="center"><?php echo($number) ?></td>
            <td align="left" style="padding-left:10px"><?php echo($name) ?></td>
            <td align="center"><?php echo($note) ?></td>
            <td align="center"><?php echo($sexe)  ?></td>
            <td align="center"><?php echo($group) ?></td>
            <td></td>
            <td>
              <a href="php/updateParticipant.php5"><img src="images/migatiEditUser20x20.jpg"></a>
              <a href="php/deleteParticipant.php5?number=<?php echo($number) ?>"><img src="images/migati_cancel16x16.png"></a>
            </td>
        </tr>
        <?php }?>
    </table>

deleteParticipant.php <?php echo ($_GET['number']); ?>

试试这个:

   <table>
    <?php
    foreach($participants as $participant)
    {
    $number = $participant->number;
    $name = $participant->name;
    $note = $participant->note;
    $sexe = $participant->sexe;
    $group = $participant->group;
    $adjust = $participant->adjust;
    ?>
    <tr>
        <td align="center"><?php echo $number; ?></td>
        <td align="left" style="padding-left:10px"><?php echo $name; ?></td>
        <td align="center"><?php echo $note; ?></td>
        <td align="center"><?php echo $sexe;  ?></td>
        <td align="center"><?php echo $group; ?></td>
        <td></td>
        <td>
          <a href="php/updateParticipant.php5"><img src="images/migatiEditUser20x20.jpg"></a>
          <a href="php/deleteParticipant.php5?number=<?php echo $number; ?>"><img src="images/migati_cancel16x16.png"></a>
        </td>
    </tr>
    <?php }?>
</table>

并在您的deleteParticipant.php使用:

<?php echo $_GET['number']; ?>

你必须知道get是如何工作的。然后从该文件调整代码deleteParticipent.php?number= <?php echo $number; ?>。您将收到它作为$_GET['number']