[PHP] Output Blank?

2008-06-23 Thread Dan Shirah
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


Re: [PHP] Output Blank?

2008-06-23 Thread Daniel Brown
On Mon, Jun 23, 2008 at 1:46 PM, Dan Shirah [EMAIL PROTECTED] wrote:

 if($numberFields) { // Check if we need to output anything
  $types = ifx_fieldtypes($query);
  if (isset($types)) {
  foreach($types as $field_name[] = $data_type) {
  }
  }

Is there a particular reason you're telling PHP that, for each
$types variable, set this key of the $field_name array to equal
$data_type, and do nothing else about it?

Is this what you meant to do for some reason?

?php

if(isset($types)) {
foreach($types as $field_name = $data_type) {
$$field_name = $data_type;

// Or should it be something like this?
$column_names[] = $field_name;
}
}

$headers = join(',', $column_names).\n;
?


-- 
/Daniel P. Brown
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Output Blank?

2008-06-23 Thread Dan Shirah
When I have = $data_type in there my column title values for $field_name
display correctly.  If I take out = $data_type it displays the the column
type. IE SQLNUMINT SQLCHAR...instead of the column title.

On 6/23/08, Daniel Brown [EMAIL PROTECTED] wrote:

 On Mon, Jun 23, 2008 at 1:46 PM, Dan Shirah [EMAIL PROTECTED] wrote:
 
  if($numberFields) { // Check if we need to output anything
   $types = ifx_fieldtypes($query);
   if (isset($types)) {
   foreach($types as $field_name[] = $data_type) {
   }
   }

Is there a particular reason you're telling PHP that, for each
 $types variable, set this key of the $field_name array to equal
 $data_type, and do nothing else about it?

Is this what you meant to do for some reason?

 ?php

 if(isset($types)) {
foreach($types as $field_name = $data_type) {
$$field_name = $data_type;

// Or should it be something like this?
$column_names[] = $field_name;
}
 }

 $headers = join(',', $column_names).\n;
 ?


 --
 /Daniel P. Brown
 Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
 $59.99/mo. with no contract!
 Dedicated servers, VPS, and hosting from $2.50/mo.



Re: [PHP] Output Blank?

2008-06-23 Thread Dan Shirah

 Is there a particular reason you're telling PHP that, for each
 $types variable, set this key of the $field_name array to equal
 $data_type, and do nothing else about it?


The ifx_fieldtypes function returns the data as an array with the field
names as the key, and the field types as the data. So, to get the column
titles to display, I am setting creating an array for the field names(key)
by passing the =.  I think?

I could rename $data_type to $apples_and_oranges or any variable name I
wanted. It just needs the reference so it knows to output the field name
instead of the field type. If I'm understanding the manual.  Yes, Dan...I
read the manual this time! :)

I believe the problem I am having is within the code below:

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

The output of print_r($info); is everything that I want to see and it is
actually there.  But when I try to get that data into an array to display in
my table, it isn't being displayed. I think I might have the syntax
incorrect for $row[] because if I type in $row[] =
parseCSVComments($info); my output displays Array in every cell.

Dan


Re: [PHP] Output Blank?

2008-06-23 Thread Jim Lucas

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



Re: [PHP] Output Blank?

2008-06-23 Thread Dan Shirah
AH HA!  Got it!

The problem was I did not need to loop through the array headers to
associate the data. So I removed:

  foreach($field_name as $fieldName) { // Loop through the array of headers
as we fetch the data
   $row[] = parseCSVComments($info-$fieldName);
  } // End loop

And ran it as:

 while($info = ifx_fetch_row($query)) {
 //print_r($info);
  $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
 }

And everything output correctly!

Dan


Re: [PHP] Output Blank?

2008-06-23 Thread Dan Shirah

// 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);



 BTW: what are you doing, if anything, if your data has a comma in it?


Jim,

I took your advice about clearing the array and resetting the $field_name
variable. Thanks!

I am not worried about comma's in my data because my application
and database do not allow comma's to be input for this information. :)

Dan