简体   繁体   中英

Export only selected columns in php

Previously it was hardcoded, but now the requirement is that I want to download only the selected columns.

In View:

foreach ($allColumnsDBArray as $colHeading) { ?>
    <input type="checkbox" class='form' name="selectedcols[]" value="<?php echo "$colHeading"; ?>" />
    <?php echo $colHeading; echo "<br>";
}

In Controller:

public function actionExport_csv() {
    $model = new Companies();
    $session = Yii::$app->session;             
    if(isset($_POST['download'])){ if(!empty($_POST['selectedcols'])) {
        foreach($_POST['selectedcols'] as $check) {
            echo $check;//what will be the code here to download column in selectedcols
         }
    } 
}

我使用导出菜单小部件导出选定的列

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM