in reply to Composing a SQL statement

just join your "foo like bar" strings with " AND ".
some other points i noticed:
  • get rid of variables like $nfields, use @fields in scalar context or $#fields to increase readability
  • you should probably quote strings in your select statements like "foo like 'bar'"
  • don't use sprintf when you don't need it: eg. $sql .= "$foo like '$bar'";

    cheers
    snowcrash //////