使用PHP将数据从SQl导出到Excel

So the admin has the choice to choose what he want to export to excel by selecting checkboxes which i stored in col[]... here's my code for exporting

 session_start();
$HOST = 'localhost';
$USERNAME = 'root';
$PASSWORD = '';
$DB = 'fyp_db';

$link = mysqli_connect($HOST, $USERNAME, $PASSWORD, $DB);

if (is_array($_POST['col'])) {
    $sql = "SELECT ";
    foreach ($_POST['col'] AS $value) {
        $sql .= "{$value}, ";
    }
    $sql = substr($sql, 0, -2);
    $sql .= " FROM account, coursedetail, coursecategory";  
    /*echo "sql= " . $sql . "<br /><br />
";*/
} else {
    echo "No column was selected<br /><br />
";
}

function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/?
/", "\
", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; }

$filename = "website_data.xls"; 
header("Content-Type: text/plain"); 
$flag = false; 
$result = mysqli_query($link, $sql) or die(mysqli_error($link));
while(false !== ($row = mysql_fetch_assoc($result))) { 
    if(!$flag) { 
    // display field/column names as first row 
    echo implode("\t", array_keys($row)) . "
"; 
    $flag = true; 
        } 
        array_walk($row, 'cleanData'); 
        echo implode("\t", array_values($row)) . "
"; 

        }

I got the error of..

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given in C:\xampp\htdocs\project\export_successful.php on line 28

why? :(

You're mixing up mysqli and mysql calls. The two libraries are NOT compatible and handles/statements returned by one cannot be used in the other.

$result = mysqli_query($link, $sql) or die(mysqli_error($link));
               ^--- note the 'i'
while(false !== ($row = mysql_fetch_assoc($result))) { 
                             ^--- note the LACK of an 'i'