简体   繁体   English

PHP多个字段使用多个运算符进行搜索

[英]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. 我正在寻找具有多个字段的搜索表单的PHP最佳解决方案,并且人也可以选择对该字段进行操作。 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. 能够通过PHP和Javascript之间的协作代码解决它。 Created array in PHP with name of field, then what type of operations it support and other optined needed. 在PHP中使用字段名称创建数组,然后说明它支持什么类型的操作以及其他需要优化的操作。

Then in jQuery hide display and restrict field options based on options that i output from PHP array. 然后在jQuery中隐藏显示并根据我从PHP数组输出的选项来限制字段选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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