简体   繁体   中英

PHP multiple fields search with multiple operators

I am looking best solution in PHP for a search form which has multiple fields and person can also choose operation on that field. Here is how it will work for example. Also allow me to set what operations are possible on field without hard-coding. There will be many fields on page i am explaining on few on them.

Scenario examples :

  • Lets field "age" there can be three scenario. age can be greater than or equal to or less than given field. So on page for a field person will be able to select operation type from drop-down "equal,greater,lesser" and then specify value.

  • Similarly for subject it can have following scenarios. subject equals selected, or in multiple selected subjects, or not in selected subjects.

I don't wanna hard-code solution for each field, i want something that's more flexible with which i can add or remove fields later without changing major part of code.

Was able to resolve it with collaborated code between PHP and Javascript. Created array in PHP with name of field, then what type of operations it support and other optined needed.

Then in jQuery hide display and restrict field options based on options that i output from PHP array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM