PHP
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives Mailing Lists PHP

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 23rd, 2008, 01:11 PM
Dan Shirah
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Output Blank?

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

Reply With Quote
  #2  
Old June 23rd, 2008, 01:51 PM
Dan Shirah
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Output Blank?

>
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, DanI
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

Reply With Quote
  #3  
Old June 23rd, 2008, 02:31 PM
Dan Shirah
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Output Blank?

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

Reply With Quote
  #4  
Old June 23rd, 2008, 02:31 PM
Dan Shirah
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Output Blank?

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

Reply With Quote
Reply

Viewing: Web Development Archives Mailing Lists PHP > Output Blank?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT