一个SQL查询活动用户和非活动用户?

There is a table in database contains username,status(active or inactive).I need to display a page contains two groups. First group will be for the active users and the second group will be for inactive users. Only one select query is permitted to use. That means no separate SQL statements for the two groups.

What you could do is just pull them all in at once, then when you write to the page you can loop trough it twice, once to echo all active users, and once to echo all inactive users. This would be a quick and dirty solution.

EDIT: Yes you can order by status and just have one loop.

just a quick example (if you've ordered it so actives are first(order by 'status' ASC)):

    echo "Active:<br /><ul>";
    $current = 'a';
    foreach($accounts as $c)
    {
        // Switch to the inactive list if your current list is still active, and your current item is inactive
        if($c->status == "inactive" && $current == 'a'){
        echo "</ul><br />Inactive<br /><ul>";
        $current = "i";
        }
        echo "<li>$c->username</li>"

    }

You can use 'if' to separate

<?php
$sql = "SELECT * FROM tblUser";
$query = mysql_query($sql);

$result = mysql_fetch_array($query);

foreach($result as $user){
    if($user['status'] == 'active'){
        //your code here...
    }else{
        //your code here...
    };
};

?>