php - Array_unique and XLS export
Get the solution ↓↓↓So I want to export my database to XLS format... Here is my code
$req_test = $db->prepare('SELECT `surname`, `name`, `num`, `email`, `password`, `rank` FROM staff');
$req_test->execute();
$array = $req_test->fetchAll();
$array = array_unique($array);
print_r($array);
header("Content-Disposition: attachment; filename=\"demo.xls\"");
header("Content-Type: application/vnd.ms-excel;");
header("Pragma: no-cache");
header("Expires: 0");
$out = fopen("php://output", 'w');
foreach ($array as $data)
{
fputcsv($out, $data,"\t");
}
fclose($out);
So without the array_unique it return this :
Array ( [0] => Array ( [surname] => test [0] => test [name] => test [1] => test [num] => 2424242424 [2] => 2424242424 [email] => [email protected] [3] => [email protected] [password] => 123456 [4] => 123456 [rank] => admin [5] => admin ) [1] => Array ( [surname] => Markus [0] => Markus [name] => Tasse [1] => Tasse [num] => 052424524 [2] => 052424524 [email] => [email protected] [3] => [email protected] [password] => us01PjIOx2 [4] => us01PjIOx2 [rank] => staff [5] => staff ) )
And with I have this error :
( ! ) Notice: Array to string conversion in C:\wamp3.2.0\www\project\export.php on line 15
What can I do ? Thanks.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: can't write image data to path
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.