View Full Version : Outputting array within an array (Excel Export)

12-01-2010, 12:05 AM
Hi guys. I am trying to setup a script which exports data into an Excel file. I am having troubles outputting arrays. It will only output the last value of an array.

I am currently using this PHP Excel class: http://code.google.com/p/php-excel/

This is the part of my code which does the exporting:

$query = "SELECT * FROM asset WHERE operational_state = 'Production' OR operational_state = 'Planned' OR operational_state = 'Expired' OR operational_state = 'Maintenance' OR operational_state = 'Repair'";
$myresult = QueryIntoArray($query);
$hostname = $myresult[$i]["hostname"];
$description = $myresult[$i]["description"];

$info = array (
1 => array ("Hostname", "Description"),
array ($hostname, $description)

// generate file (constructor parameters are optional)
$xls = new Excel_XML('UTF-8', false, 'Current Assets');

It only outputs the last value of the arrays $hostname and $description. I was playing around with the array_push() function but could not get it working properly. Any ideas how can I output whole arrays with each value in the array on a new row?

12-01-2010, 12:37 AM
$hostname = array();$description = array();
$hostname[$i] = $myresult[$i]["hostname"];
$description[$i] = $myresult[$i]["description"];
Similarly for push:
$hostname = array();$description = array();

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum