[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Help with sending data to Excel

Hello,

I have a script that runs a query and places the result in excel query.  This work fine.  I need to take this a step further.  When displaying this data directly on to a web page I parse the data so that it only displays part of the information.

Here is the code I have to generate the excel file:

export = mysql_query($query_rs_ssip_ongoing);
$fields = mysql_num_fields($export);

for ($i = 0; $i < $fields; $i++) {
    $header .= mysql_field_name($export, $i) . "\t";
}

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);

if ($data == "") {
    $data = "\n(0) Records Found!\n";                        
}

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";

------------------------------------------------

and here is the code that I use which parses the infromation when displayed on the webpage:

      <?php
                        $text1 = $row_rs_ssip_ongoing['Subject'];
                        $start1 = strpos( $text1, ">" );
                        $ends1 = strpos( $text1, "#" );
                        $eng = substr( $text1, $start1+1, ($ends1-$start1-1) );
                        echo $eng;
                        ?>

What I need to do is merge these two so that the excel output is the same as the information displayed on the website.

Any help appreciated.
0
andyw27
Asked:
andyw27
1 Solution
 
Beverley PortlockCommented:
I'm confused.

When you're displaying the spreadsheet you can't see the webpage because Excel is open in the browser so you can't see both.

Secondly, since you are apparently running exactly the same query the results should be identical. In what way do they differ?
0
 
andyw27Author Commented:

The spreadsheet downloads to the users machine.

They differ because the Excel query returns everything whereas the web page breaks down the content.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now