Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

mysql data from stored procedure to excel

php mysqli

  • Please log in to reply

#1
Qreen

Qreen

    New Member

  • Member
  • Pip
  • 1 posts

Iam trying to generate an excel file for down load with this code,but nothing is going right;

if(!isset( $_POST['data_set'])){$err='ERROR: Please select a data type!';}
else if(empty($err)){
$begin_date=$_POST['outreach_date'];
$end_date=$_POST['outreach_date2'];
    $colnames=array("Title","Project date","Description","Mandate","Project Type","Agency","Perfomance indicator");
$field_cnt = count($colnames);
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=export.xls");
header("Pragma: no-cache");
header("Expires: 0");
//$totalRecord=$field_cnt;

for ( $i = 0; $i < $field_cnt; $i++ )
{
     echo $colnames[$i]. "\t";
}print("\n");
}else{
//		if(isset($err)){
		
			echo json_encode(
				array(
				"success" => "0",
				"Error" => htmlentities($err),
				)
			);
		} 

why  am i failing to get the file download?is it because of  other data above the headers??

if i do this below, it all works fine.why is it that when i include any  data validation  it fails to work/?

	$colnames=array("Title","Project date","Description","Mandate","Project Type","Agency","Perfomance indicator");
$field_cnt = count($colnames);
for ( $i = 0; $i < $field_cnt; $i++ )
{
      $header .= $colnames[$i]. "\t";
}


// allow exported file to download forcefully
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=devzone_co_in_export.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";

Edited by Qreen, 04 February 2015 - 06:50 AM.

  • 0

Advertisements


#2
seema joshi

seema joshi

    New Member

  • Member
  • Pip
  • 5 posts

I am also facing with the same issue..Is it necessary to use header in the last part of the code


  • 0






Similar Topics


Also tagged with one or more of these keywords: php, mysqli

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP