Stacy

Try something like this:

At 16:26 04/04/2001 +1000, you wrote:

>   Hi all,
>
>   I have a perl CGI form like thus:
>
>   X | Call No   | Call No textfield
>   X | Problem  | Problem textfield
>
>   The X's represent checkboxes.
>
>   In the backend, I have two arrays:
>
>   @fields: checked fields
>   @entries: text fields with entries.
>
>   my code for generating the SQL is below. My problem
>   occurs when one enters text into more than one text
>   field. For example, say I check "Call No" and "Problem"
>   and enter "111" and "seating" into their respective
>   text fields. The SQL becomes:
>
>   SELECT call_no, problem FROM HELP WHERE
>     ( call_no LIKE 111 problem LIKE seating )
>
>   There needs to be an "AND" in the WHERE clause. The SQL
>   should read:
>
>   SELECT call_no, problem FROM HELP WHERE
>     ( call_no LIKE 111 AND problem LIKE seating )
>
>
>   I'll be stuffed if I know how to do it.
>
>   Can the monks help me???
>
>   Thanks,
>
>       Stacy.
>
>
>   ***********
>
>
>     $nfields = @fields;
>
>     foreach $i (@entries) {
>       if ($i ne '') {
>         push @full_entries, $i;
>       }
>     }
>
>     $sql = sprintf "SELECT %s FROM HELP WHERE (", join(", ", @fields);
# new line
my @where;

>     for ($j = 0; $j < $nfields; $j++) {
>       if ($full_entries[$j] ne '') {

# line modified

>         push @where, sprintf " %s LIKE %s ", $fields[$j], $full_entries[$j];
>   +
>       }
>     }

# line modified

>     $sql .= (join ' AND ', @where).')';

Reply via email to