我需要首先显示在线用户标签,然后显示所有在线用户,然后结束第一个<optgroup>
离线和空闲也是如此。
代码:
foreach($alt_user_result as $cur_user) {
if( $cur_user[user_status]=='online') {
echo "<option class='green_status' value='$cur_user[user_id]'>$cur_user[username] | $cur_user[user_status]
</option>";
}
elseif( $cur_user[user_status]=='idle') {
echo "<option class='yellow_status' value='$cur_user[user_id]'>$cur_user[username] | $cur_user[user_status]
</option>";
}
elseif( $cur_user[user_status]=='offline') {
echo "<option class='gray_status' value='$cur_user[user_id]'>$cur_user[username] | $cur_user[user_status]
</option>";
}
}
<optgroup>
例如,我之前尝试添加<option class='gray_status'
,但随后会是这样
<optgroup><option></option><optgroup>
<optgroup><option></option><optgroup>
<optgroup><option></option><optgroup>
<optgroup><option></option><optgroup>
<optgroup><option></option><optgroup>
我想要这样:
<optgroup lable="online">
<option></option>
<option></option>
<option></option>
<optgroup>
<optgroup lable="offline">
<option></option>
<option></option>
<option></option>
<optgroup>
......
询问:
$alt_user_result = execute_pdo_query("SELECT U.username, U.user_id, T.last_activity_time,
case WHEN TIMESTAMPDIFF( MINUTE, T.last_activity_time ,NOW() ) <= 5 THEN 'online'
WHEN ( TIMESTAMPDIFF( MINUTE, T.last_activity_time ,NOW() ) > 5 AND
TIMESTAMPDIFF( MINUTE, T.last_activity_time ,NOW() ) <=30 ) THEN 'idle'
ELSE 'offline' end as user_status
FROM user_skills S, users U
LEFT JOIN user_status T ON U.user_id=T.user_id
WHERE S.user_id=U.user_id and S.task_type_id=? and S.permission='Yes';",
array($tablerow['task_type_id']));
提前感谢大家的帮助!