Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/07/2006, 21:06
Avatar de Anarninquë
Anarninquë
Colaborador
 
Fecha de Ingreso: julio-2005
Ubicación: MVD | Uruguay
Mensajes: 1.096
Antigüedad: 18 años, 9 meses
Puntos: 28
problema con buscador

Hice un buscador que busca registros de mi base de datos...

Tengo 2 problemas graves con él...

Código PHP:
<?php
$nombre 
$_POST['nombre'];

$nombre str_replace('á','a',$nombre);
$nombre str_replace('é','e',$nombre);
$nombre str_replace('í','i',$nombre);
$nombre str_replace('ó','o',$nombre);
$nombre str_replace('ú','u',$nombre);
$nombre str_replace('Á','A',$nombre);
$nombre str_replace('É','E',$nombre);
$nombre str_replace('Í','I',$nombre);
$nombre str_replace('Ó','O',$nombre);
$nombre str_replace('Ú','U',$nombre);
$nombre str_replace(" ","%",$nombre);

if (
$nombre == ""){
$nombre "%";
}

$sql="SELECT * FROM comercios WHERE plan=4 And barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre."%' ORDER BY nombre;"//Con Limit 0,5 mostramos sólo los últimos 5 registros, basándonos en el campo [id]
$result=mysql_query($sql);
while (
$fila mysql_fetch_Array($result)) {
echo 
'
            <div class="ficha">
                <h2>'
.$fila["nombre"].'</h2>
                <h3>'
.$fila["categoria"].' - '.$fila["barrio"].'</h3>
                <p class="largo">'
;
                if (
$fila["img"] != ""){
                    echo 
'<img alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="fotos/'.utf8_encode ($fila["img"]).'" />';
                };
echo                
$fila["linea1"].'<br />
                    '
.$fila["linea2"].'<br />
                    '
.$fila["linea3"].'
                </p>
                <p class="corto">
                    '
.$fila["linea4"].'<br />
                    '
.$fila["linea5"].'
                </p>
                    <a href="'
.$fila["leermas"].'" target="_blank" title="'.$fila["nombre"].'"><img class="abs" alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="img/sitio_web.gif" /></a>
            </div>
'
;
}

$sql="SELECT * FROM comercios WHERE plan=3 And barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre."%' ORDER BY nombre;"//Con Limit 0,5 mostramos sólo los últimos 5 registros, basándonos en el campo [id]
$result=mysql_query($sql);
while (
$fila mysql_fetch_Array($result)) {
echo 
'
            <div class="ficha">
                <h2>'
.$fila["nombre"].'</h2>
                <h3>'
.$fila["categoria"].' - '.$fila["barrio"].'</h3>
                <p class="largo">'
;
                if (
$fila["img"] != ""){
                    echo 
'<img alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="fotos/'.utf8_encode ($fila["img"]).'" />';
                };
echo                
$fila["linea1"].'<br />
                    '
.$fila["linea2"].'<br />
                    '
.$fila["linea3"].'
                </p>
                <p class="corto">
                    '
.$fila["linea4"].'<br />
                    '
.$fila["linea5"].'
                </p>
                    <a href="index.php?pag=mostrar&id='
.$fila["id"].'" title="'.$fila["nombre"].'"><img class="abs" alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="img/leer_mas.gif" /></a>
            </div>
'
;
}

$sql="SELECT * FROM comercios WHERE plan=2 And barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre."%' ORDER BY nombre;"//Con Limit 0,5 mostramos sólo los últimos 5 registros, basándonos en el campo [id]
$result=mysql_query($sql);
while (
$fila mysql_fetch_Array($result)) {
echo 
'
            <div class="ficha">
                <h2>'
.$fila["nombre"].'</h2>
                <h3>'
.$fila["categoria"].' - '.$fila["barrio"].'</h3>
                <p class="largo">'
;
                if (
$fila["img"] != ""){
                    echo 
'<img alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="fotos/'.utf8_encode ($fila["img"]).'" />';
                };
echo                
$fila["linea1"].'<br />
                    '
.$fila["linea2"].'<br />
                    '
.$fila["linea3"].'
                </p>
                <p class="corto">
                    '
.$fila["linea4"].'<br />
                    '
.$fila["linea5"].'
                </p>
            </div>
'
;
}

$basico=mysql_query("SELECT COUNT(id) FROM comercios WHERE plan=1 And barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre."%' ORDER BY nombre;");
$hay mysql_result($basico,0,0);

if (
$hay != 0){
    echo 
"<br style='clear:both;' />";
    echo 
'<div class="contenedor_plan1">';
    
$sql="SELECT * FROM comercios WHERE plan=1 And barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre."%' ORDER BY nombre;"//Con Limit 0,5 mostramos sólo los últimos 5 registros, basándonos en el campo [id]
    
$result=mysql_query($sql);
    while (
$fila mysql_fetch_Array($result)) {
    echo 
'
                <div class="ficha2">
                    <h2>'
.$fila["nombre"].'</h2>
                    <h3>'
.$fila["categoria"].'</h3>
                    <p>'
.$fila["linea1"].'<br />
                        '
.$fila["linea2"].'<br />
                        '
.$fila["linea3"].'<br />
                        '
.$fila["linea4"].'
                    </p>
                </div>
    '
;
    }
}

$plan=mysql_query("SELECT COUNT(id) FROM comercios WHERE barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre."%'");
$total mysql_result($plan,0,0);

if (
$total == 0){
    
$nombre2 substr($nombre03);//las tres primeras letras de $nombre
    
    
$sql="SELECT * FROM comercios WHERE plan=4 And barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre2."%' ORDER BY nombre;"//Con Limit 0,5 mostramos sólo los últimos 5 registros, basándonos en el campo [id]
    
$result=mysql_query($sql);
    while (
$fila mysql_fetch_Array($result)) {
    echo 
'
                <div class="ficha">
                    <h2>'
.$fila["nombre"].'</h2>
                    <h3>'
.$fila["categoria"].' - '.$fila["barrio"].'</h3>
                    <p class="largo">'
;
                    if (
$fila["img"] != ""){
                        echo 
'<img alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="fotos/'.utf8_encode ($fila["img"]).'" />';
                    };
    echo                
$fila["linea1"].'<br />
                        '
.$fila["linea2"].'<br />
                        '
.$fila["linea3"].'
                    </p>
                    <p class="corto">
                        '
.$fila["linea4"].'<br />
                        '
.$fila["linea5"].'
                    </p>
                        <a href="'
.$fila["leermas"].'" target="_blank" title="'.$fila["nombre"].'"><img class="abs" alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="img/sitio_web.gif" /></a>
                </div>
    '
;
    }
    
    
$sql="SELECT * FROM comercios WHERE plan=3 And barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre2."%' ORDER BY nombre;"//Con Limit 0,5 mostramos sólo los últimos 5 registros, basándonos en el campo [id]
    
$result=mysql_query($sql);
    while (
$fila mysql_fetch_Array($result)) {
    echo 
'
                <div class="ficha">
                    <h2>'
.$fila["nombre"].'</h2>
                    <h3>'
.$fila["categoria"].' - '.$fila["barrio"].'</h3>
                    <p class="largo">'
;
                    if (
$fila["img"] != ""){
                        echo 
'<img alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="fotos/'.utf8_encode ($fila["img"]).'" />';
                    };
    echo                
$fila["linea1"].'<br />
                        '
.$fila["linea2"].'<br />
                        '
.$fila["linea3"].'
                    </p>
                    <p class="corto">
                        '
.$fila["linea4"].'<br />
                        '
.$fila["linea5"].'
                    </p>
                        <a href="index.php?pag=mostrar&id='
.$fila["id"].'" title="'.$fila["nombre"].'"><img class="abs" alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="img/leer_mas.gif" /></a>
                </div>
    '
;
    }

    
$sql="SELECT * FROM comercios WHERE plan=2 And barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre2."%' ORDER BY nombre;"//Con Limit 0,5 mostramos sólo los últimos 5 registros, basándonos en el campo [id]
    
$result=mysql_query($sql);
    while (
$fila mysql_fetch_Array($result)) {
    echo 
'
                <div class="ficha">
                    <h2>'
.$fila["nombre"].'</h2>
                    <h3>'
.$fila["categoria"].' - '.$fila["barrio"].'</h3>
                    <p class="largo">'
;
                    if (
$fila["img"] != ""){
                        echo 
'<img alt="'.utf8_encode ($fila["nombre"]).'" title="'.utf8_encode ($fila["nombre"]).'" src="fotos/'.utf8_encode ($fila["img"]).'" />';
                    };
    echo                
$fila["linea1"].'<br />
                        '
.$fila["linea2"].'<br />
                        '
.$fila["linea3"].'
                    </p>
                    <p class="corto">
                        '
.$fila["linea4"].'<br />
                        '
.$fila["linea5"].'
                    </p>
                </div>
    '
;
    }
    
    echo 
"<br style='clear:both;' />";
    echo 
'<div class="contenedor_plan1">';
    
$sql="SELECT * FROM comercios WHERE plan=1 And barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre2."%' ORDER BY nombre;"//Con Limit 0,5 mostramos sólo los últimos 5 registros, basándonos en el campo [id]
    
$result=mysql_query($sql);
    while (
$fila mysql_fetch_Array($result)) {
    echo 
'
                <div class="ficha2">
                    <h2>'
.$fila["nombre"].'</h2>
                    <h3>'
.$fila["categoria"].'</h3>
                    <p>'
.$fila["linea1"].'<br />
                        '
.$fila["linea2"].'<br />
                        '
.$fila["linea3"].'<br />
                        '
.$fila["linea4"].'
                    </p>
                </div>
    '
;
    }
    
    
$plan2=mysql_query("SELECT COUNT(id) FROM comercios WHERE barrio Like '".$barrio."' And categoria Like '".$categoria."' And nombre Like '%".$nombre2."%'");
    
$total2 mysql_result($plan2,0,0);
    if (
$total2 == 0){
        echo 
'
                <div class="ficha">
                    <h2>'
.utf8_encode ("Tu búsqueda no obtuvo ningún resultado.").'</h2>
                    <h3>&nbsp;</h3>
                    <p class="largo">
                        <img alt="0 resultados" src="img/busqueda_error.gif" />
                        '
.utf8_encode ("Puedes volver a intentarlo, cambiando el nombre de tu búsqueda, o dejando el campo 'Nombre' en blanco para buscar todos los comercios de una categoría o barrio.").'
                    </p>
                    <p class="corto">
                        '
.utf8_encode ("Si deseas contactarnos:<br /><a href='mailto:[email protected]' title='Ayuda'>[email protected]</a>.").'
                    </p>
                </div>
        '
;
    }
}

echo 
'</div>';
?>
__________________
Marcelo Ferreiro - Desarrollador Web
Mi Web - Pixelar.me