gpt4 book ai didi

PHP:在嵌套的foreach循环中动态显示用户的id

转载 作者:行者123 更新时间:2023-11-29 11:03:41 24 4
gpt4 key购买 nike

在我正在构建的 PHP 和 MySql CRUD 应用程序中,我有一个表显示从 “users”表中提取的数据, 如下所示:

<table class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $counter=0; foreach ($get_users as $arr){ ?>
<tr>
<td>
<?php echo ++$counter; ?>
</td>
<?php foreach ($arr as $key => $value){ ?>
<td><?php echo $value; ?></td>
<?php } ?>
<td>
<ul class="list-inline">
<li><a href="view_user.php?id=5" title="User details"><span class="glyphicon glyphicon-eye-open"></span></a></li>
<li><a href="#" title="Add data"><span class="glyphicon glyphicon-th-list"></span></a></li>
<li><a href="#" title="Delete user"><span class="glyphicon glyphicon-trash"></span></a></li>
</ul>
</td>
</tr>
<?php } ?>
</tbody>
</table>

最后一列称为“操作”,有一组用于查看、添加和删除数据的图标链接。考虑到上面的表结构,我怎样才能将用户的ID动态地写在一行上:

<li><a href="view_user.php?id=5" title="User details"><span class="glyphicon glyphicon-eye-open"></span></a></li>

最佳答案

根据您的代码,我只是假设 Id 位于 $arr 的第 0 个索引上,因此您可以执行此操作

<li><a href="view_user.php?id=<?php echo $arr[0];?>" title="User details"><span class="glyphicon glyphicon-eye-open"></span></a></li>

关于PHP:在嵌套的foreach循环中动态显示用户的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41776553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com