At 20:23 20.11.2002, Mr. BuNgL3 said:
--------------------[snip]--------------------
>Hi...
>I'm with a little sintax problem...
>The question is that i have two search fields (titulotxt and cdstxt) and i
>want to create an mysql condition... i trying:
>
> $sql1=($titulotxt) ? "titulo like '%".$titulotxt."%'":"";
> $sql2=($cdstxt) ? "cds like '$cdstxt'":"";
> $sql="SELECT * FROM divx WHERE" .$sql1 " && " .$sql2 " ORDER BY titulo";
>
>but the bastard is giving me a sintax error on the 3 line... Can anyone
>teach me how i must do to validate the mysql condition and make it work?
--------------------[snip]-------------------- 

As already said, put a space after the WHERE clause.

What happens if $sql1 or $sql2 are empty (as your example provisons)?
Create an $sql3 that combines $sql1 and $sql2, and construct your SQL
accordingly:

    $sql1 = ($titulotxt ? null : "titulo like '%$titulotxt%'");
    $sql2 = ($cdstxt    ? null : "cds like '$cdstxt'");
    $sql3 = $sql1 . ($sql1 && $sql2 ? ' AND ' : null) . $sql2;
    $sql  = 'SELECT * FROM divx ' .
            ($sql3 ? "WHERE $sql3 " : null) . 
            'ORDER BY titulo';



-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to