Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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