首页 > 解决方案 > 使用 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>

标签: phphtmlcss

解决方案


使用 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>

推荐阅读