从MySQL数据库中的行显示文本等于0和1?

时间:2014-12-27 16:28:33

标签: php mysql sql rows fetch

我无法让我的代码显示来自MySQL数据库的文本,它等于0和1.如果它显示“/ * 1 =登录* /”我希望它显示'特权'等于的结果0和1,但我不知道如何。

   <?php
if (isset($_SESSION['username']))
   {
   if($_SESSION['privileges'] == '1') /* 1 = logged in */
    {
    $sql="SELECT * FROM `navbar`";
    $sql2=mysql_query($sql)
          or die("Couldn't etablish connection with
                 the server or username wasn't found 
                 in the database.");
    $count=mysql_num_rows($sql2);
    if($count > 0)
     {
      while ($row = mysql_fetch_assoc($sql2)) {
        if(($row['privileges'] == '0') or ($row['privileges'] == '1'))
          {
           echo '<li><a href="', $row["url"], '">', $row["text"], '</a></li>';
          }
      }
     }else{
          die("Could't find 'navbar' table in database.");
     }
    }
    else if($_SESSION['privileges'] == '2') /* 2 = vip */
         {
          include('./navbar_vip.php');
         }
          else if($_SESSION['privileges'] == '3')  /* 3 = supporter */
           {
            include('./navbar_support.php');
           }
            else if($_SESSION['privileges'] == '99')  /* 99 = administrator */
             {
             include('./navbar_admin.php');
             }
      }
?>

1 个答案:

答案 0 :(得分:0)

首先 你需要

  1. -catch $ _SESSION ['privileges'],如isset($_SESSION['privileges'])
  2. 而不是3,如果使用开关

    switch($_SESSION['privileges']){
    case 1: /* logged */
      ...
      default: /* not logged in */
    
    }
    
  3. 更改if(($row['privileges'] == '0') or ($row['privileges'] == '1'))

    if(($ row ['privileges'] =='0')||($ row ['privileges'] =='1'))

  4. “或”只是因为你的意思是OR运算符:“||”