Page 1 of 1

converting PHP DB records to excel file...

Posted: Tue Jul 05, 2005 10:03 pm
by darkcrimson
I have preview page that shows simple details of properties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed.

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected)

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: appere is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; filename=excelfile.xls&quote;);
header(&quote;Pragma: no-cache&quote;);
header(&quote;Expireted. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want  you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quotties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the that shows simple details of properties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&que that shows simple details of properties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; filename=excelfile.xls& option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

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";
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('"', '""', $value);
# needed to encapsulate data in quotes because some data might byou for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&ae details of properties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/ocrom the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

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";
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('"', '""', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '"' . $value . '"' . "\t";
    }
    $line .= $value;
  }
  $data .= trim($line)."\n";
}
# this line is needed because returns embedded in the data have "\r"
# and this looks like a "box character" in Excel
  $data = str_replace("\r", "", $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == "") {
  $data = "\nno matching records found\n";
}

# This line will stream the file to the user rather than spray it across the screen
header("Content-type: application/octet-stream");

# replace excelfile.xls with whatever you want the filename to default to
header("Content-Disposition: attachment; filename=excelfile.xls");
heyou can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; filename=excelfile.xls&quote;);
header(&quote;Pragma: no-cache&quote;);
header(&quote;Expires: 0&quote;);

echo $header.&quote;\n&quote;.$data;
?&gt;



any ideas? :confused:ert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected)

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

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";
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('"', '""', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '"' . $value . '"' . "\t";
    }
    $line .= $value;
  }
  $data .= trim($line)."\n";
}
# this line is needed because returns embedded in the data have "\r"
# and tect records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; filename=excelfile.xls&quote;);
header(&amprice etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; filename=excelfile.xls&quote;);
header(&quote;Pragma: no-cache&quote;);
header(&quoe that shows simple details of properties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

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";
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encaddress, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

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";
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('"', '""', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '"' . $value . '"' . "\t";
    }
    $line .= $value;
  }
  $data .= trim($line)."\n";
}
# this line is needed because returns embedded in the data have "\r"
# and this looks like a "box character" in Excel
  $data = str_replace("\r", "", $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == "") {
  $data = "\nno matching records found\n";
}

# This line will stream the file to the user rather than spray it across the screen
header("Content-type: application/octet-stream");

# replace excelfile.xls with whatever you want the filename to default to
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");

echo $header."\n".$data;
?>
re not selected disappear. If you click details link in depth details are listed.

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected)

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

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";
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('"', '""', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '"' . $value . '"' . "\t";
    }
    $line .= $value;
  }
  $data .= trim($line)."\n";
}
# this line is needed because returns embedded in the that shows simple details of properties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the columf properties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; filename=excelfile.xls&quote;);
header(&quote;Pragma: no-cache&quote;);
header(&quote;Expires: 0&quote;);
ption on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; filename=excelfile.xls&quote;);
header(&quote;Pragma: no-cache&quote;);
header(&quote;Expires: 0&qhis page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever yoe that shows simple details of properties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; filename=excelfile.xls&quote;);
header(&quote;Pragma: no-cache&quote;);
header(&quote;Expires: 0&quote;);

erecords 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == ""){
      $value = "\t";
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quotetails link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; filename=excelfile.xls&quote;);
header(&quote;Pragma: no-cache&quote;);
header(&quote;Expires: 0&quote;);

echo $header.&amnvert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data =  you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

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";
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('"', '""', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '"' . $value . '"' . "\t";
    }
    $line .= $value;
  }
  $data .= trim($line)."\n";
}
# this line is needed because returns embedded in the data have "\r"
# and this looks like a "box character" in Excel
  $data = str_replace("\r", "", $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == "") {d disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&quote;);

# replace excelfile.xls with whatever you want the filename to default to
header(&quote;Content-Disposition: attachment; properties. you can see address, price etc.. There is a sort option on this page where you for example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

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 == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# thfor example select records 1,3,12,10 and click a button and all of records that are not selected disappear. If you click details link in depth details are listed. 

I need to find a way to convert these records from the PHP DB to an excel file.

I found a script that will convert the entire table to a excel file but I need to find a method that will only convert certain records (the ones that are selected) 

here is that code, I figure it might be a good place to start:

Code: Select all

&lt;?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include('DB_connection.php');
$result = mysql_query('select * from excel_test', $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i &lt; $count; $i++){
    $header .= mysql_field_name($result, $i).&quote;\t&quote;;
}

while($row = mysql_fetch_row($result)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == &quote;&quote;){
      $value = &quote;\t&quote;;
    }else{
# important to escape any quotes to preserve them in the data.
      $value = str_replace('&quote;', '&quote;&quote;', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
      $value = '&quote;' . $value . '&quote;' . &quote;\t&quote;;
    }
    $line .= $value;
  }
  $data .= trim($line).&quote;\n&quote;;
}
# this line is needed because returns embedded in the data have &quote;\r&quote;
# and this looks like a &quote;box character&quote; in Excel
  $data = str_replace(&quote;\r&quote;, &quote;&quote;, $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == &quote;&quote;) {
  $data = &quote;\nno matching records found\n&quote;;
}

# This line will stream the file to the user rather than spray it across the screen
header(&quote;Content-type: application/octet-stream&qu

Posted: Tue Jul 05, 2005 11:34 pm
by hawleyjr
You will not be able to just convert to Excel. Create a CSV file which can be opened by Excel.