nerd99 Posted August 11, 2010 Share Posted August 11, 2010 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210493-the-argument-should-be-an-array/ Share on other sites More sharing options...
schilly Posted August 11, 2010 Share Posted August 11, 2010 Did you look at the output your echoing? Or print out your row arrays to see if they are correct? Quote Link to comment https://forums.phpfreaks.com/topic/210493-the-argument-should-be-an-array/#findComment-1098313 Share on other sites More sharing options...
nerd99 Posted August 12, 2010 Author Share Posted August 12, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/210493-the-argument-should-be-an-array/#findComment-1098318 Share on other sites More sharing options...
schilly Posted August 12, 2010 Share Posted August 12, 2010 Comment the header tags, print_r the $row array and look at the source code it spits out in your browser. Quote Link to comment https://forums.phpfreaks.com/topic/210493-the-argument-should-be-an-array/#findComment-1098550 Share on other sites More sharing options...
void Posted August 12, 2010 Share Posted August 12, 2010 mysqli_query($connection,"SELECT * FROM students ORDER BY tutor") not too sure about mysqli, bet for mysql_query the first argument is query and the second one is conn link. Quote Link to comment https://forums.phpfreaks.com/topic/210493-the-argument-should-be-an-array/#findComment-1098572 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.