从sql查询中省略数组

时间:2014-10-13 20:43:40

标签: php sql

我正在显示我网站上“缺席玩家”的列表,目前只删除了列表中显示的“admin”用户名。我添加了一组“非活动玩家”,但我不知道如何从sql查询中省略该数组。

以下是代码:

//display list of absent players
$sql = "select * from " . $db_prefix . "users where userID not in(" . implode(',', array_keys($playerTotals)) . ") and userName <> 'admin'";
$query = mysql_query($sql);
if (mysql_num_rows($query) > 0) {
    $absentHtml = '<p style="color: #7a7a7a; position: relative"><b>Absent Players:</b> ';
    $i = 0;
    while ($result = mysql_fetch_array($query)) {
        if ($i > 0) $absentHtml .= ', ';
        switch ($user_names_display) {
            case 1:
                $absentHtml .= trim($result['firstname'] . ' ' . $result['lastname']);
                break;
            case 2:
                $absentHtml .= $result['userName'];
                break;
            default: //3
                $absentHtml .= '<abbrev title="' . trim($result['firstname'] . ' ' . $result['lastname']) . '">' . $result['userName'] . '</abbrev>';
                break;
        }
        $i++;
    }
    echo $absentHtml; 

位于其他地方的数组看起来像这样:

//list of inactive users
$inactiveUsers = array('user1','user2','user3');

正如您所看到的,and userName <> 'admin'省略了“admin”名称,但我不知道如何同时添加数组$ inactiveUsers。

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

$sql = "select * from ".$db_prefix."users
where userID not in (".implode(',', array_keys($playerTotals)).")
and userName not in ('admin', '".implode("','", $inactiveUsers)."')";
相关问题