将数据显示到HTML表格PHP中

时间:2016-12-22 13:15:21

标签: php html mysql

我正在从MySQl数据库中检索数据并将其显示到HTML表格中,并且工作正常。 对于每一行,我有一个按钮,单击它时显示当前行的详细信息。 这对于期望第一行的所有行都很好,当我点击按钮时#34;编辑"它确实会将我重定向到详细信息页面。

请帮忙! This is the index page with the list of persons :

这是显示人员列表并重定向到页面的代码"编辑"点击"编辑"按钮



<table border = 1> 
 <caption> Liste des personnes </caption> 
  <tr><th>id </th><th>nom</th><th>prenom</th><th>date Naissance</th><th>sexe</th><th>ville</th><th>comptence</th><th>photo</th></tr>
    <?php
    while ($obj = mysqli_fetch_object($result)){
    ?> 
    <tr ><td> <?= $obj->id ?> </td><td><?= $obj->nom?></td><td><?= $obj->prenom?></td><td><?= $obj->dateNaissance?></td>
    <td><?= $obj->sexe?></td><td><?= $obj->ville?></td> <td><?= $obj->competence?></td>
   
     <?php 
    if (isset($obj->photo)) {?>
    <td><img src="uploads/<?= $obj->photo?>" width =20 height = 20 >
    <?php 
      }
    ?>
    <td>
        <form name="editPerson" action="edit.php" method="POST">
            <input type="hidden" name="id" value="<?=  $obj->id  ?>">
            <input type="submit" name="editer" value="Edit">
        </form>
    </td>
    </tr>
    <?php 
        }
    ?>
 </table>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

首先在表格行中显示数据,你应该回显。 单击编辑按钮时,您可以通过GET方法将数据传递到详细信息页面。 <a href="details.php?id=".$obj->id">edit </a>

details.php页面中的

通过$_GET['id']获取id。查询id = $_GET['id']行,并通过fetch assoc函数将值加载到输入字段。 例如:

<input value="<?php echo $obj->nom;?>" name="nom">
相关问题