How can I implement user-friendly boolean logic in a web form GUI?

Miguel picture Miguel · Nov 9, 2009 · Viewed 20.7k times · Source

Currently I have a web application where a user can use dropdown lists to generate SQL SELECT statements like so:

Column Select Dropdown | Operator Dropdown (= != > < <= >=) | Value select dropdown

The user can do this multiple times, and the "filters" are currently all ANDed together.

I want to add the possibility of creating OR statements. I could very easily add ORs in the case where the columns are the same, but what about complex logic statements like

((A OR B OR C) AND (D OR E)) OR (F AND G)?

How can I let users create such statements in a user-friendly way?

EDIT: To specify, user-friendly for a general audience. Currently I work with developers that occasionally hand-code SQL queries for a non-technical client that needs specific information from our database. The goal is that this web app will remove the need for us to hand-code them by giving the client an easy-to-use tool to do it themselves.

EDIT2: Currently the app is not being used by end users. The only data I have as to its use are previous handwritten SQL queries and thus the kind of queries the client asks for. Given that I could simplify it (e.g. limit the users' ability to generate queries to the kinds of queries they tend to ask for), but I want to see if anybody has experience communicating boolean logic simply and completely in GUIs.

Thank you for your time.

Answer

dryobs picture dryobs · Mar 22, 2016

There is a jquery plugin to do this, called QueryBuilder, which do this in an interesting way : http://mistic100.github.io/jQuery-QueryBuilder/

Jquery QueryBuilder Screenshot