Jump to content

Recommended Posts

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

?>

 

 

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>" ; }

......

}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.