php - Member list omit Admin Account from List -
i working on website , have basic table display members of people have registered. don't want display admin account on table. there way exclude username/id table in case, admin? in advanced, josh
here code member list table:
<?php include("include/session.php"); /** * displayusers - displays users database table in * 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 userlevel desc,username"; $result = $database->query($q); /* error occurred, return given name 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"; } ?>
just update query:
$q = "select username,userlevel,email,timestamp " ."from ".tbl_users." userlevel<>'admin' order userlevel desc,username";
if use pdo library:
... $adminlevel = 'admin'; $q = "select username,userlevel,email,timestamp " ."from ".tbl_users." userlevel <> ? order userlevel desc,username"; $statement = $database->prepare($q); $result = $statement->execute(array($adminlevel)); ... // go on rest of code
Comments
Post a Comment