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 18th, 2008, 06:31 PM
Dan Shirah
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Exporting to Excel

Hello all,

I am trying to query an INFRMIX database, and then take the results and
export them into a CSV or Excel file. I saw TNS of examples on how to do
this using MySQL and tried to adpt them for ifx, but I can't get the darn
thing working. My code below sets variables for values passed from my form.
I then connect to my database and run a query that gets results based on the
variable values. After that I want to count the number of fields(columns)
and begin to build the export file.

Well, when I execute the page I get the popup to save/open the output as an
Excel file. When I open it, instead of getting data, it returns an error
message of: PHP Warning: Wrong parameter count for ifx_fieldtypes()

I am trying to use ifx_fieldtypes() to replace the mysql function of
mysql_field_name()

Any ideas?

<?php
$name_code = $_PST['name'];
// echo $name_code;
$case_age = $_PST['case_age'];
// echo $case_age;
$case_cat = $_PST['case_cat'];
// echo $case_cat;
$case_status = $_PST['case_status'];
// echo $case_status;
include 'Conn/prpr_ifx.php';
if (!$connect_id = ifx_connect("$database@$host", $user, $pass)) { // THE
ACTUAL CNNECTIN
echo "Unable to connect to Informix Database\n"; // DISPLAY IF
CNNECTIN FAILS
exit();
}

function parseCSVComments($comments) {
$comments = str_replace('"', '""', $comments); // First off escape all "
and make them ""
if(eregi(",", $comments) or eregi("\n", $comments)) { // Check if I have
any commas or new lines
return '"'.$comments.'"'; // If I have new lines or commas escape them
} else {
return $comments; // If no new lines or commas just return the value
}
}
$sql = "SELECT * FRM pending_summary_detail WHERE name = '$name_code'";
if (!empty($case_age)) {
$sql.=" AND case_age_group = '$case_age'";
}
if (!empty($case_cat)) {
$sql.=" AND case_category = '$case_cat'";
}
if (!empty($case_status)) {
$sql.=" AND case_status = '$case_status'";
} // Start our query of the database

$query = ifx_query ($sql, $connect_id);
$numberFields = ifx_num_fields($query); // Find out how many fields we are
fetching

if($numberFields) { // Check if we need to output anything
for($i=0; $i<$numberFields; $i++) {
$head[] = ifx_fieldtypes($query, $i); // Create the headers for each
column, this is the field name in the database
}
$headers = join(',', $head)."\n"; // Make our first row in the CSV

while($info = ifx_fetch_row($query)) {
foreach($head 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;
} else {
// Nothing needed to be output. Put an error message here or something.
echo 'No data available for this CSV.';
}
?>

Reply With Quote
Reply

Viewing: Web Development Archives Mailing Lists PHP > Exporting to Excel


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-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT