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 />\n";*/
} else {
echo "No column was selected<br /><br />\n";
}
function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $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)) . "\r\n";
$flag = true;
}
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\r\n";
}
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? :(