Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/10/2014, 15:06
Avatar de herzbazi
herzbazi
 
Fecha de Ingreso: febrero-2012
Mensajes: 612
Antigüedad: 13 años
Puntos: 36
Pregunta errores de tildes y ñ al descargar archivo

necesito que cuando se descargue o exporte la tabla mysql a el excel este ponga bien las tildes y las ñ

ya he probado
Código PHP:
Ver original
  1. header('Content-Type: text/html; charset=UTF-8');
pero no funciona si me pueden ayudar diciendome por donde tengo el error o bien diciendome cual es mi error , agradecido estare...


Código PHP:
Ver original
  1. <?php
  2. //conexion a base de datos MySql  
  3. include_once("../class/class.php");
  4. if(isset($_SESSION['admin2']))
  5. {
  6. $sql = "SELECT * FROM contacto ORDER BY fecha ASC";
  7. $r = mysql_query( $sql ) or trigger_error( mysql_error($conexion), E_USER_ERROR ); $return = ''; if( mysql_num_rows($r)>0){
  8.   $return .= '<table border=1>';
  9. $cols = 0;
  10. while($rs = mysql_fetch_row($r)){
  11.     $return .= '<tr>';
  12.     if($cols==0){
  13.         $cols = sizeof($rs);
  14.         $cols_names = array();
  15.         for($i=0; $i<$cols; $i++){
  16.             $col_name = mysql_field_name($r,$i);
  17.             $return .= '<th>'.htmlspecialchars($col_name).'</th>';
  18.             $cols_names[$i] = $col_name;
  19.         }
  20.         $return .= '</tr><tr>';
  21.     }
  22.     for($i=0; $i<$cols; $i++){
  23.         #En esta iteraci車n podes manejar de manera personalizada datos, por ejemplo:
  24.        if($cols_names[$i] == 'fechaAlta'){ #Fromateo el registro en formato Timestamp
  25.            $return .= '<td>'.htmlspecialchars(date('d/m/Y H:i:s',$rs[$i])).'</td>';
  26.         }else if($cols_names[$i] == 'activo'){ #Estado l車gico del registro, en vez de 1 o 0 le muestro Si o No.
  27.            $return .= '<td>'.htmlspecialchars( $rs[$i]==1? 'SI':'NO' ).'</td>';
  28.         }else{
  29.             $return .= '<td>'.htmlspecialchars($rs[$i]).'</td>';
  30.         }
  31.     }
  32.     $return .= '</tr>';
  33. }
  34. $return .= '</table>';
  35.  }
  36. header("Content-type: application/vnd-ms-excel; charset=iso-8859-1");
  37. header("Content-Disposition: attachment; filename=ContactosWeb_".date('d-m-Y').".xls"); echo $return;
  38. }
  39. else
  40. {
  41.    ?>
  42.   <!doctype html>
  43.   <html lang="en">
  44.   <head><meta http-equiv="Content-Type" content="text/html; charset=big5">
  45.    
  46.     <title>Document</title>
  47.     <style>
  48.       h1{
  49.         text-align: center;
  50.         margin-top: 14%;
  51.         color:#fff;
  52.       }
  53.       h1 a{
  54.         color: #fff;
  55.       }
  56.     </style>
  57.   </head>
  58. <body style="background-color:#254584;">
  59.     <h1>Debes loguearte en <a href='index.php'>el formulario de login</a> para poder acceder.</h1>
  60. </body>
  61. </html>
  62. <?php
  63. }
  64. ?>
__________________
Enseña todo lo que sepas...
Aprende todo lo que puedas..

Última edición por herzbazi; 01/10/2014 a las 15:13 Razón: highlight