vfragk Posted October 25, 2008 Share Posted October 25, 2008 im having problem as i exporting results from query to excel. from MYSQL database set at utf_general_si and encoding of php file at utf8 Data includes greek characters that dont look as they should. Here is the code that i use <?php header('Content-type: text/html; charset=utf-8'); header("Content-Type: application/vnd.ms-excel; name='excel'"); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=E6R8.xls"); header("Pragma: no-cache"); header("Expires: 0"); $tmima = $_GET['tmima']; $data = $_GET['data']; $xronos = $_GET['years']; $tmima=$_POST['tmima']; $data=$_POST['data']; $xronos=$_POST['years']; include '../config.php'; include '../opendb.php'; // combine dynamic the query from user's selected fields $query = "SELECT ΟΝΟΜΑ_ΤΜΗΜΑΤΟΣ,ΕΤΟΣ " ; $data=$_POST['data']; if ($data){ foreach ($data as $d){$query = $query . ", $d"; } $query = $query . " FROM tmimata1"; } $query = $query . " WHERE ("; $tmima=$_POST['tmima']; if ($tmima){ foreach ($tmima as $t){$query = $query . "ΟΝΟΜΑ_ΤΜΗΜΑΤΟΣ='$t' OR ";} $query = substr_replace($query,"",-3); }//afairei ta 3 last $query = $query . " ) AND ( "; if ($xronos){ foreach ($xronos as $x){$query = $query . "ΕΤΟΣ=$x OR ";} $query = substr_replace($query,"",-3); } $query = $query . ") "; $result = mysql_query($query); $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{ $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data2 .= trim($line)."\n"; } $data2 = str_replace("\r", "", $data2); if ($data2 == "") { $data2 = "\nno matching records found\n"; } echo $header."\n".$data2; include '../closedb.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/130105-php-query-export-to-excel-with-wrong-encoding/ Share on other sites More sharing options...
kenshintomoe225 Posted October 25, 2008 Share Posted October 25, 2008 can you post a screen or something of the error you are seeing? Quote Link to comment https://forums.phpfreaks.com/topic/130105-php-query-export-to-excel-with-wrong-encoding/#findComment-674640 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 How are the characters messed up? P.S: If you speak Greek better than English, contact me over PM or just post in this thread and I'll help you out. Quote Link to comment https://forums.phpfreaks.com/topic/130105-php-query-export-to-excel-with-wrong-encoding/#findComment-674646 Share on other sites More sharing options...
vfragk Posted October 26, 2008 Author Share Posted October 26, 2008 i attached a screen shot of excel file that is exporting with results headers and name witch are at greek are not shown as they should. also i checked again the php.ini file is sets utf-8 encoding and the same character set is been at mysql (collation utf8_general_ci). What is wrong when it goes to excel? Because when i'm just echoing the results of the query with the following code is shown up fine at screen all my data. <?php ....... $result = mysql_query($query); $count = mysql_num_rows($result3); echo "ΣΥΝΟΛΟ ΕΓΓΡΑΦΩΝ : ".$count." <br>" ; while($row3 = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row3 ['ΟΝΟΜΑ_ΤΜΗΜΑΤΟΣ']!=="" ){echo "ΤΜΗΜΑ : ".$row3 ['ΟΝΟΜΑ_ΤΜΗΜΑΤΟΣ']." <br>" ;} if ($row3 ['ΕΤΟΣ']!=="0" & $row3 ['ΕΤΟΣ']!=="" ){echo "ΕΤΟΣ :".$row3 ['ΕΤΟΣ']." <br>" ;} if ($row3 ['ΑΡ_Citations']!=="0" & $row3 ['ΑΡ_Citations']!==""){echo "ΑΡ_Citations :".$row3 ['ΑΡ_Citations']." <br>" ; } ...... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130105-php-query-export-to-excel-with-wrong-encoding/#findComment-674958 Share on other sites More sharing options...
vfragk Posted October 26, 2008 Author Share Posted October 26, 2008 excel screenshot greek results [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/130105-php-query-export-to-excel-with-wrong-encoding/#findComment-674959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.