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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.