Jump to content
Sign in to follow this  
anand.arjunan

How to generate the report in excel formet

Recommended Posts

Hi all The php out put file i want generate the excel format please tell me any idea
<?php if($_REQUEST[zip]==1){ $select = "SELECT order_id,od_date,contact_person,office_name,office_add,menu,zipcode FROM orders where order_date between '".$_REQUEST[acd]."' and '".$_REQUEST[end_acd]."' and type='Rep' order by zipcode"; $export = mysql_query($select); $fields = mysql_num_fields($export);}else{ $select = "SELECT order_id,od_date,contact_person,office_name,office_add,menu,zipcode FROM orders where order_date between '".$_REQUEST[acd]."' and '".$_REQUEST[end_acd]."' and type='Rep'"; $export = mysql_query($select); $fields = mysql_num_fields($export); }?><?php $header = 'Order No'. "\t";$header .= 'Order Date'. "\t";$header .= 'Contact Person'. "\t";$header .= 'Office Name'. "\t";$header .= 'Office Address'. "\t";$header .= 'Menu'. "\t";$header .= 'Zip code'. "\t"; /* for ($i = 0; $i < $fields; $i++) { $header .= mysql_field_name($export, $i) . "\t"; } */?> <?php while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); ?> <?php if ($data == "") { $data = "\n(0) Records Found!\n"; } ?><?php header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=Reporders.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; ?>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...