Ver Mensaje Individual
  #6 (permalink)  
Antiguo 19/08/2015, 13:48
Avatar de Polu
Polu
 
Fecha de Ingreso: febrero-2003
Mensajes: 135
Antigüedad: 21 años, 2 meses
Puntos: 0
Respuesta: Mi buscador no muestra ecentos y ñ

Efectivamente gnzsoloyo, el problema está en el buscador.

mysql_query("SET NAMES 'utf8'") no lo pongo en la consulta porque si no, no devuelve las palabras con acentos y ñ correctamente sólo lo utilizo para insertar datos en la db.

Este es el script completo de la tabla que muestra los resultados de la db y del buscador:

Código PHP:
<?php
error_reporting
(E_ALL^E_NOTICE);
include(
'pagination_class.php');
mysql_connect('localhost''user''pass') or die(mysql_error());
mysql_select_db('db');

$headers "Content-type: text/html; charset=UTF-8";

?>
<script language="JavaScript" src="pagination.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<?


//ESTA ES LA ESTRUCTURA DEL BUSCADOR EN LA DB. UTILIZA LA VARIABLE "search_text".


$qry "SELECT * FROM clientes ";
$searchText "";
if(
$_REQUEST['search_text']!=""){
    
$searchText utf8_encode($_REQUEST['search_text']);
    
$qry .=" where ID like '$searchText%' 
            or nombre like '$searchText%'
            or apellidos like '$searchText%'  
            or empresa like '$searchText%'
            or ciudad like '$searchText%'
            or telefono like '$searchText%'
            or email like '$searchText%'
            or fecha like '$searchText%'"
;
}



//para la paginación
$starting=0;
$recpage 20;//número de registros por página
    
$obj = new pagination_class($qry,$starting,$recpage);        
$result $obj->result;

            
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<style type="text/css">
<!--
body {
    background-color: #FCEBD1;
}
.Estilo1 {color: #7A9801}
.Estilo2 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    color: #333333;
    font-weight: bold;
    font-size: 13px;
}
-->
</style><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Prueba Base Libros</title>

            <link href="estilos.css" rel="stylesheet" type="text/css" />
<body>

  <script language="JavaScript">
function confirmar(url){
if (!confirm("¿Estás seguro de que deseas eliminar el registro?")) {
return false;
}
else {
document.location= url;
return true;
}
}
</script>            
            
<form name="form1" action="basedatos.php" method="POST">
            
            <table border="0" align="center" width="1024">
            <tr>
              <TD colspan="2" rowspan="3"><img src="images/cabecera.jpg" alt="ImgCabecera" width="642" height="113" /></TD>
              <TD width="12%" colspan="-1">&nbsp;</TD>
            </tr>
            <tr>
              <TD colspan="-1">&nbsp;</TD>
            </tr>
            <tr>
              <TD colspan="-1">&nbsp;</TD>
            </tr>
            <tr>
              <TD colspan="3">&nbsp;</TD>
              </tr>
            <tr>
              <TD width="37%">
                <span class="Estilo2">Buscar</span>              
                <input type="text" name="search_text" value="<?php echo utf8_encode($searchText); ?>"/>                <input type="submit" value="Buscar" />                  </TD>
              <TD width="51%"><span class="Estilo1"><a href="basedatos.php" class="link">Reiniciar </a>|<a href="ingresar.php" class="a:link"> Nuevo Registro </a>| <a href="exel.php" class="link"> Exportar a Excel</a></span></TD>
              <TD>&nbsp;</TD>
            </tr>
            <tr><TD colspan="3">
            
            <div id="page_contents">
              <table border="0" align="center" width="100%">
              
<tr class="titulos">
<td width="17">Id</td>
<td width="68">Nombre</td>
<td width="140">Apellidos</td>
<td width="140">Empresa</td>
<td width="101">Ciudad</td>
<td width="95">Tel&eacute;fono</td>
<td width="181">E-mail</td>
<td width="69">Fecha</td>
<td colspan="2">Operaciones</td>
</tr>
                <?
                
if(mysql_num_rows($result)!=0){
$counter $starting 1;
$headers "Content-type: text/html; charset=UTF-8";
while(
$data mysql_fetch_array($result)) {
              
    
printf("<tr class=letra_y_fondo_consulta >   
    <td>%s</td>
    <td>%s</td>
    <td>%s</td>
    <td>%s</td>
    <td>%s</td>
    <td>%s</td>
    <td>%s</td>
    <td>%s</td>    
    </tr>"
utf8_encode ($data["ID"]), utf8_encode ($data["nombre"]), utf8_encode ($data["apellidos"]), utf8_encode ($data["empresa"]), utf8_encode ($data["ciudad"]), utf8_encode ($data["telefono"]), utf8_encode ($data["email"]), utf8_encode ($data["fecha"]));
        
?> 
  



<?

    


?>
                <tr>
                  <td colspan="4"><? echo $obj->anchors?></td>
                </tr>
                <tr>
                  <td colspan="4"><? echo $obj->total?></td>
                </tr>
                <?
                
}else{
                
?>
                <tr>
                  <td align="center" colspan="4">No hay datos disponibles</td>
                </tr>
                <?
                
}
                
?>
              </table>
            </div>
            </TD></tr>
  </table>
            <h6>&nbsp;</h6>
</form>
</body>
</html>

Última edición por Polu; 19/08/2015 a las 13:52 Razón: se me ha olvidado código