php - PHP:如果某些条件为真,则显示元素
问题描述
基本上我需要只有在管理员登录时才能看到带有删除和编辑按钮的列,我知道如何确定管理员是否登录。有没有办法回显需要显示的标签?提前致谢!
<table>
<tr>
<th>ID</th>
<th>Full Name</th>
<th>Email Address</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Status</th>
<th>Edit?</th>
<th>Delete?</th>
</tr>
<?php foreach ($users as $user) : ?>
<tr>
<td><?php echo $user->getUser_id();?></td>
<td><?php echo $user->getFirstName().' '.$user->getLastName();?></td>
<td><?php echo $user->getEmailAddress(); ?></td>
<td><?php echo $user->getAddress();?></td>
<td><?php echo $user->getCity(); ?></td>
<td><?php echo $user->getState(); ?></td>
<td><?php echo $user->getZipCode(); ?></td>
<td><?php echo $user->getActiveDescription();?></td>
these two <td> should only be shown if x is true:
<td>
<form action ="" method="post">
<input type="hidden" name="controllerRequest"
value="show_user_edit">
<input type="hidden" name="user_id"
value="<?php echo $user->getUser_id(); ?>"/>
<input type="submit" value="Edit"></form>
</td>
<td>
<form action="" method="post">
<input type="hidden" name="controllerRequest"
value="delete_user">
<input type="hidden" name="user_id"
value="<?php echo $user->getUser_id(); ?>"/>
<input type="submit" value="Delete" id="red">
</form>
</td>"
;
}
}
?>
</tr>
<?php endforeach; ?>
</table>
解决方案
需要使用看看:https<?php if(x): ?>
: //www.php.net/manual/en/control-structures.if.php#112231<?php endif ?>
推荐阅读
- c++ - 在“以防万一”的所有类值副本上使用 std::move 是代码气味吗?
- terraform - terraform depends_on 用于路线 53 区域关联
- linux - 在 Debial Linux 9.5 下通过 ACL 权限设置文件夹/文件的特定权限的问题
- reactjs - 如何在不同的 Vercel 项目中托管 React 应用程序
- python - 有什么办法可以在“x for y in x for z”中获得 x
- kaltura - Kaltura Iframe 嵌入:无法读取 null 的属性“功能”
- html - 混合整个页面
- python - 如何在 Heroku 中终止 Python 机器人
- encryption - 压缩还是加密?
- python - 如何从 Tkinter for Python 3.x 中的 Text 小部件获取段落数据?如何获取用户的段落输入并将数据添加到 CSV 文件?