Dan Shirah wrote:
Having some issues with outputting my table data as an array. In the code below I am outputting the column titles of my table into an excel spreadsheet. I get the column titles just fine in Excel. if($numberFields) { // Check if we need to output anything $types = ifx_fieldtypes($query); if (isset($types)) { foreach($types as $field_name[] => $data_type) { } } $headers = join(',', $field_name)."\n"; // Make our first row in the CSV After that I am pulling all of the column data to place under it's respective title. Uncommenting the print_r($info); below does display all of the data for each column correctly. However, after I run my foreach loop and output the report to Excel all I get is empty rows/columns where the data should be...on the bright side I get the exact number of empty rows that my query should return. Any ideas why the data isn't populating? If I change $row[] = parseCSVComments($info->$fieldName); to $row[] = parseCSVComments($info); I get "Array" printed out in every cell. while($info = ifx_fetch_row($query)) { //print_r($info); foreach($field_name as $fieldName) { // Loop through the array of headers as we fetch the data $row[] = parseCSVComments($info->$fieldName); } // End loop $data .= join(',', $row)."\n"; // Create a new row of data and append it to the last row $row = ''; // Clear the contents of the $row variable to start a new row } // Start our output of the CSV header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=data.csv"); header("Pragma: no-cache"); header("Expires: 0"); echo $headers.$data; } Thanks, Dan
<?php while($info = ifx_fetch_row($query)) { //print_r($info); // Initialize/clear the contents of the $row variable $row = array(); // You probably need to reset the $field_name var with each // iteration over it. from what I understand, foreach will move // the internal pointer of the array to the end. Then the next // iteration over the array will start at the end. BAD!!! reset($field_name); // Loop through the array of headers as we fetch the data foreach($field_name as $fieldName) { // From the manual: ifx_fetch_row returns an associative array $row[] = parseCSVComments($info[$fieldName]); } // End loop // Create a new row of data and append it to the last row $data .= join(',', $row)."\n"; } // End while ?> BTW: what are you doing, if anything, if your data has a comma in it? -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php