doupeng8494 2016-09-03 13:01
浏览 41

基于HTML中设置的数据过滤器构建通用PHP / MySQL查询

I'm trying to find the best way to make "filtering" of my data. Filters are set by input fields on front end, and based on that filters (inputs) i need to build query in PHP and retrieve data from MySQL database.

This would be easy if i had only one page and one query where i filter data, but i have more pages which pull data from everywhere around database.

What i have in my mind is to build front end HTML forms, with inputs corresponding to database fields, and then when i get form posted, to go via

if(some_field != '')
$q .= ' AND some_field = some_field_value';

problem is i have some fields which should be compared with LIKE and it only gets more complex introducing more fields and values..

I'm sure that there must be better approach to this problem.

I wonder, is there any good example of best practise to similar data filtering?

  • 写回答

1条回答 默认 最新

  • duan117890 2016-09-03 13:37
    关注

    What I understand is that you have different pages that you want your backend to cater to? And that some of these pages have similar fields but possible to have two pages with different need of query statement(= vs LIKE)? You may include a hidden field that you check in the php code if it needs to use the query statement with LIKE. It will really be complex since you are trying to cater to varying situations and filter fields.

    What I did to my filtering is tackle it one filter for each entity...so for example, I have customer module, it has different filter to Purchase Order module...

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动