0

我正在我的网站上工作,我有一个基本表格来显示已注册的人的成员。但是,我不想在表格上显示管理员帐户。在这种情况下,管理员有什么方法可以从表中排除用户名/ID?非常感谢,乔希

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

<?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";


}
?> 
4

2 回答 2

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
于 2013-07-24T04:42:30.053 回答
0

You can modify this accordingly..

SELECT * FROM table WHERE level <> 'admin'
于 2013-07-24T04:44:41.747 回答