Jump to content

The argument should be an array...


nerd99

Recommended Posts

Hi,

 

I am attempting to export some table data to an excel spreadsheet. I am having trouble with the final few lines and getting the following error within the spreadsheet (which is otherwise working well).

 

The argument should be an array in/home/website/public_html/student_list_export.php on line 34

I get the same error message for the line below also (echo implode("\t", array_values($row)) . "\n";).

 

I'm at a loss. This seems like a pretty obvious and direct error message but I can't get it working properly. Can somebody please help me?

 

Below is the code I am working with.

<?php 

include('includes/admin_session.php');

require_once("includes/connection.php"); 

function cleanData(&$str) {

  $str = preg_replace("/\t/", "\\t", $str);
  $str = preg_replace("/\r?\n/", "\\n", $str);

  if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';

}
// file name for download
$filename = "student_list_" . date('Ymd') . ".xls";

header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");

$flag = false;

$result = mysqli_query($connection,"SELECT * FROM students ORDER BY tutor") or die(mysqli_error($connection));

while(false !== ($row = mysqli_fetch_assoc($result))) {
  if(!$flag) { // display field/column names as first row
    echo implode("\t", array_keys($row)) . "\n";
    $flag = true;
  }
  array_walk($row, 'cleanData');
  echo implode("\t", array_values($row)) . "\n";
  
  }
  
  ?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/210493-the-argument-should-be-an-array/
Share on other sites

Hi, thanks for having a look at this.

 

The output successfully downloads the excel file with all of the data I request...However, when downloading (or exporting) it gets stuck on the lines mentioned above and continues to export error messages. When I stop the download, I can open the excel spreadsheet - all the info I want is laid out on the page but printed below are the two error messages repeated over and over...

 

Any ideas?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.