我有一个管理区域,他们可以一次删除多个用户。这是处理删除的代码的一部分。基本上,它会通过用户 ID 并删除每个标记为已检查的用户 ID。
if ($_POST['doDelete'] == 'Delete') {
if (!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
$id = escape($uid);
$delete = Nemesis::query("DELETE FROM users WHERE id = '{$id}' AND id <> '{$_SESSION[user_id]}'");
if (!$delete) {
$msg->add('e', QUERY_ERROR);
redirect('users.php');
exit();
}
}
}
/* we need a way to iterate over users deleted */
$msg = new Messages();
$msg->add('s', QUERY_DELETE_SUCCESS);
redirect('users.php');
exit();
}
function get_user_name_from_id($user_id)
{
if ($_SESSION['user_level'] == ADMIN_LEVEL) {
$viewUserMod = 1;
} else {
$config = Nemesis::select("usr_view_cm", "config");
$row_config = $config->fetch_assoc();
$viewUserMod = $row_config['usr_view_cm'];
}
if (is_numeric($user_id) && $viewUserMod == 1) {
$sql = Nemesis::select("full_name", "users", "id = {$user_id}");
if ($sql->num_rows > 0) {
$user_name = $sql->fetch_assoc();
return $user_name['full_name'];
} else {
// user name cannot be matched with db, either error, or most likely user was deleted
return 'User ' . $user_id;
}
} else {
return $user_id;
}
}
它说QUERY_DELETE_SUCCESS
我想输出诸如“已删除的 Bob,Jack,Tim”之类的内容。等我有一个函数,它使用用户 ID 并获取他们的名字。问题是一旦迭代完成。显然,这些用户不再存在于数据库中,我无法得到他们的名字。有没有办法在循环期间运行这个函数,并构建一个字符串或数组。那可以代替消息输出吗?