Greetings....

i would just like to ask a favor regarding on
php-mysql-excell format....
i'm using the php as my programming language with the
following information:

System SunOS repair-c 5.9
PHP Version 4.3.2

and for mysql as my database, its:
mysqladmin  Ver 8.23 Distrib 3.23.58

below is the php script that i used to get the data
from the database and save it as excell document.

my problem is the language from my database, they
inputted some english and japanese language....

whenever i've open the file in staroffice, it can read
the nihongo, however when i open it in microsoft
office, it turns out that the nihongo are something
like a garbage character.....

any suggestions would highly appreciated.... thanks
and best regards....


erwin

============================================================
<?php

//EDIT YOUR MySQL Connection Info:
$DB_Server = "";                //your MySQL Server 
$DB_Username = "";                  //your MySQL User
Name 
$DB_Password = "";                //your MySQL
Password 
$DB_DBName = "";            //your MySQL Database Name

$DB_TBLName = "";                    //your MySQL
Table Name 


//DEFINE SQL QUERY:
//you can use just about ANY kind of select statement
you want - 
//edit this to suit your needs!
$sql = "Select * from $DB_TBLName";


//create MySQL connection
$Connect = @mysql_connect($DB_Server, $DB_Username,
$DB_Password)
    or die("Couldn't connect to MySQL:<br>" .
mysql_error() . "<br>" . mysql_errno());
//select database
$Db = @mysql_select_db($DB_DBName, $Connect)
    or die("Couldn't select database:<br>" .
mysql_error(). "<br>" . mysql_errno());
//execute query
$result = @mysql_query($sql,$Connect)
    or die("Couldn't execute query:<br>" .
mysql_error(). "<br>" . mysql_errno());


$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=hello.xls");
header("Pragma: no-cache");
header("Expires: 0");

echo $header."\n".$data;
?>



__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

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

Reply via email to