hi all,

onclick a link i am exporting all details to excel. it's working well.
but when i uploaded this file to my domain and run it,it is fetching data but not all data, columns are exporing to excel but only first 3 value are exporting to excel.

any idea for this appre..

$cdate = date("Y-m-d"); // get current date
$obj=new process();
$query_string = "SELECT user_register.user_id as Sno,job_apply,name as Name,Email,Country,Age,Address,Cno as ContactNumber,Mno as MobileNumber,Gender,Date_register as RegisterDate,filename as Document FROM user_register join user_upload on user_register.user_id=user_upload.user_id"; 
$export_filename = "report_$cdate.xls";

$result = mysql_query($query_string);

$count = mysql_num_fields($result);

$header = '';
for ($i = 0; $i < $count; $i++){
	$header .= mysql_field_name($result, $i)."\t";

while($row = mysql_fetch_row($result)){
	$line = '';
	foreach($row as $value){
		if(!isset($value) || $value == ""){
			$value = "\t";
			$value = str_replace('"', '""', $value);
			$value = '"' . $value . '"' . "\t";

		$line .= $value;
	$data .= trim($line)."\n";

$data = str_replace("\r", "", $data);

if ($data == "") {
	$data = "\nNo Data Found\n";

// create table header showing to download a xls (excel) file
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$export_filename");
header("Cache-Control: public");
header("Content-length: ".strlen($data)); // tells file size
header("Pragma: no-cache");
header("Expires: 0");
// output data
echo $header."\n".$data;
8 Years
Discussion Span
Last Post by mangel.murti

echo $query_string; exit;
Check sql query on your domain and execute in sql window, what you are getting?


echo $query_string; exit;
Check sql query on your domain and execute in sql window, what you are getting?

i already check this before but as u told me i checked it again , if i did any mistake

but query fetching all data from mysql but when printing data to excel table column are there and only 3 values fetching to excel.

please see image attached.


Attachments query.JPG 48.63 KB

It might be broken in between.
Post your database record and your current excel.

i cannot upload excel file here , i inserted some records to my server ,so sending exported output of excel in jpg formet and
query result

Attachments excel_export_result.JPG 129.4 KB fetch_domain_query_result.JPG 91.12 KB

Change Line no. 40 to

header("Content-Type: application/vnd.ms-excel");

i did this but no result , same thing happing....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.