在foreach中删除一行

问题描述 投票:0回答:1

我正在使用php CRM,以下代码导出数据库中所有用户的列表(此列表由管理员用户显示)

foreach ($rResult as $aRow) {
$row = array();
for ($i = 0; $i < count($aColumns); $i++) {
    if (strpos($aColumns[$i], 'as') !== false && !isset($aRow[$aColumns[$i]])) {
        $_data = $aRow[strafter($aColumns[$i], 'as ')];
    } else {
        $_data = $aRow[$aColumns[$i]];
    }
    if ($aColumns[$i] == 'last_login') {
        if ($_data != null) {
            $_data = time_ago($_data);
        } else {
            $_data = 'Never';
        }
    } elseif ($aColumns[$i] == 'active') {
        $checked = '';
        if ($aRow['active'] == 1) {
            $checked = 'checked';
        }

        $_data = '<div class="onoffswitch">
            <input type="checkbox" data-switch-url="'.admin_url().'staff/change_staff_status" name="onoffswitch" class="onoffswitch-checkbox" id="c_'.$aRow['staffid'].'" data-id="'.$aRow['staffid'].'" ' . $checked . '>
            <label class="onoffswitch-label" for="c_'.$aRow['staffid'].'"></label>
        </div>';

        // For exporting
        $_data .= '<span class="hide">' . ($checked == 'checked' ? _l('is_active_export') : _l('is_not_active_export')) . '</span>';
    } elseif ($aColumns[$i] == 'firstname') {
        $_data = '<a href="' . admin_url('staff/profile/' . $aRow['staffid']) . '">' . staff_profile_image($aRow['staffid'], array(
            'staff-profile-image-small'
            )) . '</a>';
        $_data .= ' <a href="' . admin_url('staff/member/' . $aRow['staffid']) . '">' . $aRow['firstname'] . ' ' . $aRow['lastname'] . '</a>';
    } elseif ($aColumns[$i] == 'email') {
        $_data = '<a href="mailto:' . $_data . '">' . $_data . '</a>';
    } else {
        if (strpos($aColumns[$i], 'date_picker_') !== false) {
            $_data = (strpos($_data, ' ') !== false ? _dt($_data) : _d($_data));
        }
    }
    $row[] = $_data;
}
$options = icon_btn('staff/member/' . $aRow['staffid'], 'pencil-square-o');
if (has_permission('staff', '', 'delete') && $output['iTotalRecords'] > 1 && $aRow['staffid'] != get_staff_user_id()) {
    $options .= icon_btn('#', 'remove', 'btn-danger', array(
        'onclick'=>'delete_staff_member('.$aRow['staffid'].'); return false;',
        ));
}
 $row[]              = $options;
 $output['aaData'][] = $row;
}

数据库中有5个管理员;

我想隐藏一个使用staffid = 1作为后门的用户。

如何使用此staffid删除行?

(我不熟悉PHP编码)

谢谢

php foreach row delete-row
1个回答
0
投票

您可以添加如下if()条件: -

foreach ($rResult as $aRow) {
  if($aRow['staffid'] !=1){
    //complete code inside if
  }
}

注意: - 我认为$aRowstaffid作为索引

© www.soinside.com 2019 - 2024. All rights reserved.