php - 使用 varchar 数据确定何时在 php/html/css 中设置 div 类的显示
问题描述
目前在 css 我有.box2{display:none;}
,这会将包含链接的框设置deletecustomer.php
为不可见。当用户导航到此页面(customerprofile.php)时,我希望它检查customer
存储在“用户”表中的 varchar 变量。数据是“是”或“否”。当数据说“不”时,我想设置"display:true"
,但我不确定在哪里放置那行代码或如何编写它。它是查询还是 if 语句?
<head>
<title>Edit Customer</title>
<link href = "../css/style.css" type = "text/css" rel = "stylesheet" />
<style type="text/css">
body {
background-color: #0F9;
}
h1 {
color: #000;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body text="#000000">
<?php
include ('dbconnect.php');
?>
<div class = "wholepage">
<div class = "box">
<?php
include ('header.php');
?>
<?php
$query ="select userid,customer
from users
where username= '$username'
and customer ='$customer'";
$infos = array();
$result = mysqli_query($db, $query);
if ($result){
while ($rows = mysqli_fetch_assoc($result)){
$infos[] = $rows;
}
foreach ($infos as $info){
$userid = $info['userid'];
}
}
$query = "select *
from users
where userid= ' $userid'
order by userid";
$result = mysqli_query($db,$query);
if ($result){
while ($rows = mysqli_fetch_array($result))
{
?>
**<div class ='box2'>
<p>Staff Access </p>
<div align="right">
<div align="right"><a href ="deletecustomer.php?userid=<?php echo $rows[0]; ?>">Delete </a>
</div>**
</div>
</div>
<h2>User Information</h2>
<p>Here you may view your current account information and may edit or delete the account. </p>
<table width="98%" border="1" cellpadding="1" >
<tr>
<th width="405"><div align="left"><u>User ID</u></div></th>
<th width="331"> <div align="center"><u><?php echo $rows[0]; ?> </u></div></th>
</tr>
<tr>
<th><div align="left"><u>User Name</u></div></th>
<td width="331"> <div align="center"><u><?php echo $rows[1]; ?> </u></div></td>
</tr>
<tr>
<th><div align="left"><u>User Password</u></div></th>
<td width="331"> <div align="center"><u><?php echo $rows[2]; ?> </u></div></td>
</tr>
<tr>
<th><div align="left"><u>First Name </u></div></th>
<td width="331"> <div align="center"><u><?php echo $rows[3]; ?> </u></div></td>
</tr>
<tr>
<th><div align="left"><u>Last Name</u></div></th>
<td width="331"> <div align="center"><u><?php echo $rows[4]; ?> </u></div></td>
</tr>
<tr>
<th><div align="left"><u>User Address</u></div></th>
<td width="331"> <div align="center"><u><?php echo $rows[5]; ?> </u></div></td>
</tr>
<tr>
<th><div align="left"><u>Customer? </u></div></th>
<td width="331"> <div align="center"><u><?php echo $rows[7]; ?> </u></div></td>
</tr>
<tr>
<th> <div align="left"><u>User Telephone </u></div></th>
<td width="331"> <div align="center"><u><?php echo $rows[6]; ?> </u></div></td>
<td width="195">
<u><a href ="deletecustomer.php?userid=<?php echo $rows[0]; ?>">Delete </a>
|
<a href ="editcustomer.php?userid=<?php echo $rows[0]; ?>">Edit </a>
</u></td>
</tr>
<?php
}
}
?>
</table>
</div>
</div>
</body>
</html>
解决方案
使用 php 代替 css。检查 $row['customer'] 是或否。如果是,则显示删除链接。
<td width="195">
<u>
<?php if($rows['customer'] == "yes") { ?>
<a href ="deletecustomer.php?userid=<?php echo $rows[0]; ?>">Delete </a> |
<?php } ?>
<a href ="editcustomer.php?userid=<?php echo $rows[0]; ?>">Edit </a>
</u>
</td>
推荐阅读
- python - 如何使用 Python / Pandas 在 Excel 中插入新行(有条件)
- java - Java 最佳实践静态最终映射值
- docker - 当它高于某个内存限制时重新启动 docker 容器?
- python-3.x - 使用 Python 文档创建虚拟环境
- xslt - 如何代表给定数字创建元素?
- php - PHP segfault - 如何获取 php 文件和行号?
- ssl - Apache:cURL:ssl3_get_record:apache2 ssl 的版本号错误
- excel - 运行时错误“1004”:保存文件后对象“_Worksheet”的方法“范围”失败
- c# - 如何在 EF 中执行更新级联
- cordova - API 密钥错误 变量“GOOGLE_MAPS_IOS_API_KEY”未注册