Re: export data to a ms excel file using php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



gopi krishnan wrote:
> Dear all,
> 
> I found the solution for my problem.
> try this core...
> 
> -----------------------------------------------------------------------------------------------------------------------
> 
> <?php
> #Setting MIME Type in header
> /*header("Content-Type:  application/vnd.ms-excel"); */
> header("Content-Type:  application/vnd.ms-excel");
> header("Expires: 0");
> /*header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); */
> header("Cache-Control: must-revalidate");
> 
> 
> # Connecting to oracle server
> $dbh = oci_connect ('TESTDB', 'TESTDB', '//192.168.3.197/ORCL');
> 
> # Querry for fetching the column names
> $stmt = oci_parse ($dbh, "Select COLUMN_NAME from user_tab_columns where
> table_name='EMPLOYEE'");
> 
> # Execution of above statement
> oci_execute ($stmt);
> $cnt = 1;
> 
> # Fetching column names and printing
> while ($result = oci_fetch_array($stmt)) {
>     echo $result['COLUMN_NAME'] . ",";
>     $cnt = $cnt +1;
> }
> # Make a new line to write the record sets in the next line
> echo "\n";
> 
> # Querry for fetching the recors sets
> $stmt = oci_parse ($dbh, 'select * from employee');
> 
> # Here we execute the statement:
> oci_execute ($stmt);
> $cnt = 1;
> /*echo '<table border="1">';*/
> # Then we fetch rows in a loop until we're done
> while ($result = oci_fetch_array($stmt)) {
>     /*echo "gopi, gopi, gopi, gopi, gopi, gopi, gopi \n";*/
>    /*echo "Employee id " . $result['EID'] . " " . $result['FNAME'] . " " .
> $result['LNAME'] . $result["SALARY"] ."<br>";*/
>    echo $result['EID'] . "," . $result['FNAME'] . "," . $result['LNAME'] .
> "," . $result["SALARY"] ."\n";
>    $cnt = $cnt +1;
> }
> /*echo '</table>';*/
> # last we close the database handle
> oci_close($dbh);
> ?>
> 
> -----------------------------------------------------------------------------------------------------------------------
> 

This would be correct.  But, just to point out, you have a column count
mismatch.  You have 4 data fields that you are populating with 3 commas
separating them.  Yet in the column headers, you are outputting (i assume) 4
column headers with an extra comma at the end.  I'm not sure what difference
it would make your case.

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux