Php mysql if/else shorthand


Php mysql if/else shorthand

谁能看出这个速记与下面的问题有什么问题?

echo "<td><font size=1 color=#e4d6b5>" . ($row['tier']<$_SESSIONS['tier'] ? "ACCESS DENIED" : $row['contents']) . "</font></td>";

我的数据库中有两个表:

1.) 会员(ID,用户名,电子邮件,密码,盐,等级) <级是用户的安全许可级别。>

2.) Opwire(类别,内容,日期,用户ID,安全级别) <-Opwire存储用户提交的数据,UserID只是一个引用刚刚向Opwire提交数据的用户的数字。安全级别是用户需要查看特定行提交数据的安全许可级别(层)的高度。

我正在尝试根据当前登录的用户的安全层(引用成员的层与 opwire 的安全层)授予或限制对"内容"的访问权限。 我也不完全有信心我正在使用 http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL

我通常通过以下方式获取当前用户:

$userId = $_SESSION['user_id'];

整个表构建 php 如下。 目前,具有任何层的用户都可以错误地查看任何安全级别内容,而其层应对其进行限制。

<?php 
include_once 'functions.php';
include_once 'db_connect.php';
sec_session_start();
if(login_check($mysqli) == true) {
$con=mysqli_connect("localhost","mylogin","mypassword","mysqldatabase");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

function getColor($strOption)
{
   switch ($strOption)
   {
       case "Case 1":
       return "#cbae80";
       case "Case 2":
       return "#e59350";
       case "Case 3":
       return "#b7aaa4";
    }
}

$result = mysqli_query($con,"SELECT opwire.*,members.username FROM opwire 
          LEFT JOIN members on opwire.userid=members.id order by date DESC");
echo "<table border='1'>
<tr>
<th>Category</th>
<th>Contents</th>
<th>Date/Time</th>
<th>Operative</th>
</tr>";
while($row = mysqli_fetch_array($result))
 {
 echo "<tr>";
 echo "<td><font size=1 color='".getColor($row['category'])."'> " . $row['category'] . "</font></td>";
 echo "<td><font size=1 color=#e4d6b5>" . ($row['tier']<$_SESSIONS['tier'] ? "ACCESS DENIED" : $row['contents']) . "</font></td>";
 echo "<td><font size=1 color=silver>" . $row['date'] . "</font></td>";
 echo "<td><font size=1 color=gold>" . $row['username'] . "</font></td>";
 echo "</tr>";
 }
echo "</table>";
mysqli_close($con);
} else {
   echo 'Access to this area requires security clearance. <br/>';
}
?>
我相信

您需要在每个案例的末尾都有"BREAK",否则它将一直下降到"#b7aaa4";

function getColor($strOption)
 {
  switch ($strOption)
  {
   case "Case 1":
   return "#cbae80";
   break;
   case "Case 2":
   return "#e59350";
   break;
   case "Case 3":
   return "#b7aaa4";
   break;
  }
}