I need to build an app (PHP/MySQL but I don’t think it matters), letting a user to input a set of rules matching particular products. That should look like a form, allowing to select a key and to input its value, but supporting grouping with OR and AND statements. For example the user should be able to input the following product rules: (price over 100 and red color) or (price over 50 and green color), weight over 2 and so on. The problem is, I’m not sure how should I store that in the database and not sure how to code UI for that. Is there any common approach to solving such a problem?
Thanks
I’ve been thinking about that for a while. Here’s what I came to:
There is a rule table:
Your example rule can be expressed in this way:
You will then be referencing the complex rule with
rule_id=7. To resolve that rule, each other rule should be resolved recursively.fieldcan be a field in a database, as well as theoperand. You would then be able to form SQL queries from this saved data. It’s also easy to load and present into controls, so the user can edit this rule using combo boxes (HTML<select>) and stuff.