while-获取数组|如何获得每个输出的代码?

时间:2019-07-19 02:29:01

标签: php while-loop

我正在制作一个系统,我需要查看每个学生的信息。当我单击按钮时,我需要知道学生的代码并打开包含学生信息的页面(seeStudent.php)。有人可以帮我吗?

<?php

$sql = $conn->query("SELECT * from tb_coordinator inner join tb_teacher
on tb_coordinator.cd_coord = tb_teacher.cd_coord
inner join teacher_class on
tb_teacher.cd_teacher = teacher_class.cd_teacher
inner join tb_teacher on
teacher_class.cd_class = tb_class.cd_class 
inner join tb_student on
tb_class.cd_class = tb_student.cd_class
where tb_teacher.cd_cpf = '$cpf' and nm_class = '3a1'  order by cd_number asc");

while($row = mysqli_fetch_array($sql)){
    $nm_student = $row['nm_student'];
    $cd_number = $row['cd_number'];
?>


<ul class="list-group list-group-flush" style="width: 50%; margin-top: 2%;">
    <div id="load_student">
      <li class="list-group-item"><?php echo $cd_number . " - " . $nm_student;?>
       <a href="students.php" ><button type="button" class="btn btn-outline-info" style="margin-left: 90%;">Get Information</button></a></li>
    </div>
</ul>

</div>
<?php }?>

1 个答案:

答案 0 :(得分:1)

您需要在准备好的HTML中进行一些修改。将所需的参数添加到锚点href中,这可能有助于您从seeStudent.php页的数据库中获取学生详细信息。

<ul class="list-group list-group-flush" style="width: 50%; margin-top: 2%;">
    <div id="load_student">
        <li class="list-group-item"><?php echo $cd_number . " - " . $nm_student;?>
            <a href="seeStudent.php?cd_number=<?=$cd_number?>&nm_student=<?=$nm_student?>" >
                <button type="button" class="btn btn-outline-info" style="margin-left: 90%;">Get Information</button>
            </a>
        </li>
    </div>
</ul>

如果您单击Get Information按钮,将使用两个seeStudent.php参数($_GET)带您进入cd_number, nm_student

现在完成最后一个任务。在seeStudent.php页面中,从$_GET数组中获取参数,并执行其他查询以从数据库中获取学生详细信息并进行显示。

seeStudent.php

<?php
    $cd_number = isset($_GET['cd_number']) ? $_GET['cd_number'] : '';
    $nm_student= isset($_GET['nm_student']) ? $_GET['nm_student'] : '';

    // .... code stuff, possibly query and display
?>