1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[Help]Weird problem with LIKE...OR search

Discussion in 'PHP' started by elegy2009, Feb 10, 2010.

  1. #1
    When I submit just one term to the search system, the search condition 'aprovar' = '1' is ignored. But when I submit two or more words,
    this same condition is respected. . Take a look at my code and see if you find any error, please!
    I put an echo before mysql runs, and I got:
    select id,Nombre,Imagen,Visitas,Votantes,Puntos,Categoria,Thumb from neww WHERE Aprobar = '1' and Nombre LIKE '%word%' OR Categoria LIKE '%word%' OR Descripcion LIKE '%word%' OR Etiquetas LIKE '%word%' order by Visitas desc limit 0,32

    It should work and show only results with Aprobar='1', but it show also results with Aprobar='0' !!

    Please, help me! Thanks

    
    function Ordenar_Columna_LIKE(){
    
    	if(count($this->Listado) == 0){
    	$this->Seleccion_Campos = "WHERE Aprovar = '1' and ";
    	}
    	else {
    	    $this->Selecao_Campos = "WHERE Aprovar = '1' and ";
    	foreach($this->Listado as $valor){
                $this->Selecao_Campos .= $valor." LIKE '%" .  $this->Ablucion($this->Busqueda)  . "%' OR ";
    	}
    }
    
    return substr($this->Selecao_Campos,0,-4);
    
    
     
    function Consulta_LIKE(){
    
    	if(!eregi("^[0-9]+$",$this->MostrarResultados)) { $this->MostrarResultados = '10'; }
    
    $this->Consulta  = "select " .  $this->Selecao  . " from " .  $this->TabeladeBusca . " ";
    $this->Consulta .= "" .  $this->Ordenar_Columna_LIKE()  . " ";
    $this->Consulta .= " order by Visitas desc limit " . $this->PaginaInicial() . ","  . $this->MostrarResultados .  ""; 
    
    return($this->Consulta);
    PHP:

     
    Last edited: Feb 10, 2010
    elegy2009, Feb 10, 2010 IP
  2. po_taka

    po_taka Peon

    Messages:
    14
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try
    Aprobar = '1' and (Nombre LIKE '%word%' OR Categoria LIKE '%word%' OR Descripcion LIKE '%word%' OR Etiquetas LIKE '%word%')
     
    po_taka, Feb 10, 2010 IP
    sarahk likes this.
  3. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #3
    +1 for nice use of giant parentheses.
     
    SmallPotatoes, Feb 13, 2010 IP