douyingbei1458 2014-01-27 05:24
浏览 28
已采纳

在php中动态获取数据

I have a search form which has four filter textboxes. What I want to do is whenever the user submits the form, only those textboxes that has values will be submitted and searched for. I know how to do it in if else statement, but it's too long to write it in code. Is there any other shorter methods?

  • 写回答

3条回答 默认 最新

  • duandian8251 2014-01-27 06:31
    关注

    Try to use this code. You can implement search condition in the foreach loop.

    // HTML field names
    $fields = array_flip(array("search1", "search2", "search3", "search4"));
    
    $data = array_filter(array_intersect_key($_POST, $fields));
    
    foreach ($data as $key => $val) {
        // Here you can implement the sql search condtion
        echo "$key => $val" . PHP_EOL;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿