Take a look at this search builder (above the table): https://editor.datatables.net/examples/extensions/searchBuilderPreDefined.html

Does anything like that exist for PHP?

I'm looking for a proper "filtering" framework that allows a non-coder to build many such sets of rules so I can save them and later use them to filter (exclude/include) "massive" arrays containing product data coming from a db.

I know I can copy the ui, generate the rules as php code and execute them with eval() server-side but I'm looking for something that relies on functions, etc.

edit: If you use the ui to build a "query" like in this image


the following will be generated

searchBuilder[criteria][0][criteria][0][condition]: =
searchBuilder[criteria][0][criteria][0][origData]: office
searchBuilder[criteria][0][criteria][0][value1]: Tokyo
searchBuilder[criteria][0][criteria][1][condition]: contains
searchBuilder[criteria][0][criteria][1][origData]: first_name
searchBuilder[criteria][0][criteria][1][value1]: a
searchBuilder[criteria][0][logic]: AND
searchBuilder[criteria][1][condition]: contains
searchBuilder[criteria][1][origData]: last_name
searchBuilder[criteria][1][value1]: a
searchBuilder[logic]: AND

that will then be sent to the backend to generate this part of the sql query

WHERE ((`office` = 'Tokyo' AND  `first_name` LIKE '%a%') AND  `last_name` LIKE '%a%')

that then gets executed and returns the matching db data to the frontend.

I want a php script that takes the searchBuilder[...] stuff and uses them to filter an array (by unsetting/dropping non-matching values, for example).

But, I don't want to create an if (($arr['office'] === 'Tokyo' &&..... that will be passed to eval(), I want proper php functions that use the searchBuilder[...] to filter an array that contains all the db data.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Dec 19, 2022 at 19:04
  • It would be easier for others to answer your question, if you were to summarise the requirements instead of posting a link. Commented Dec 19, 2022 at 19:05
  • @RohitGupta The link is the summary, but I have added a more detailed example. Commented Dec 19, 2022 at 21:05
  • 1
    Great, and I have upvoted it. Commented Dec 19, 2022 at 22:06


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.