会员列表省略列表中的管理员帐户

时间:2013-07-24 04:32:04

标签: php html login member

我正在我的网站上工作,我有一个基本的表格来显示已注册的人员。但是我不想在桌面上显示管理员帐户。在这种情况下,管理员有没有办法从表中排除用户名/ ID?谢谢先进的Josh

这是我的成员列表表的代码:

<?php 

    include("include/session.php");

/**
 * displayUsers - Displays the users database table in
 * a nicely formatted html table.
 */
function displayUsers(){

      $levels = array('1'=>'Member','2'=>'Supporter','3'=>'Donor','4'=>'VIP','5'=>'Veteran','7'=>'Co-Founder','8'=>'Founder','9'=>'Admin');
    //do_query
    //loop results
    $ulevel = mysql_result($result,$i,"userlevel"); $ulevel = $levels[$ulevel];
    //continue loop

   global $database;
   $q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   /* Display table contents */
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Last Active</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = $levels[mysql_result($result,$i,"userlevel")];
      $time   = mysql_result($result,$i,"timestamp");

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$time</td></tr>\n";
   }
   echo "</table><br>\n";


}
?> 

2 个答案:

答案 0 :(得分:3)

只需更新您的查询:

$q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." where userlevel<>'Admin' ORDER BY userlevel DESC,username";

如果您使用PDO库:

...
$adminLevel = 'Admin';
$q = "SELECT username,userlevel,email,timestamp "
     ."FROM ".TBL_USERS." where userlevel <> ? ORDER BY userlevel DESC,username";
$statement = $database->prepare($q);  
$result = $statement->execute(array($adminLevel));

... // Go on with the rest of your code

答案 1 :(得分:0)

您可以相应地修改它。

SELECT * FROM table WHERE level <> 'admin'